Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用Zend从Facebook导入联系人_Php_Facebook_Zend Framework_Import Contacts - Fatal编程技术网

Php 如何使用Zend从Facebook导入联系人

Php 如何使用Zend从Facebook导入联系人,php,facebook,zend-framework,import-contacts,Php,Facebook,Zend Framework,Import Contacts,我正在使用Zend,我想从facebook导入联系人,我正在为此使用一个插件,它与gmail完美配合。当我尝试从facebook导入联系人时,它会完美地显示我的个人资料,但联系人列表是空的……我如何解决这个问题? 抱歉,代码太多了 <?php $config = 'hybridauth/hybridauth/config.php'; require_once( "hybridauth/hybridauth/Hybrid/Auth.php" );

我正在使用Zend,我想从facebook导入联系人,我正在为此使用一个插件,它与gmail完美配合。当我尝试从facebook导入联系人时,它会完美地显示我的个人资料,但联系人列表是空的……我如何解决这个问题? 抱歉,代码太多了

  <?php
    $config = 'hybridauth/hybridauth/config.php';

    require_once( "hybridauth/hybridauth/Hybrid/Auth.php" );       
    $error = "";           
    if (isset($_GET["error"])) {    
        $error = '<b style="color:red">' . trim(strip_tags($_GET["error"])) . '</b><br /><br />';
    }            
    if (isset($_GET["provider"]) && $_GET["provider"]):    
        try {    

            $hybridauth = new Hybrid_Auth($config);           

            $provider = @ trim(strip_tags($_GET["provider"]));           

            $adapter = $hybridauth->authenticate($provider);           

            $hybridauth->redirect("../message/profile?provider=$provider");
        } catch (Exception $e) {    
            // In case we have errors 6 or 7, then we have to use Hybrid_Provider_Adapter::logout() to 

            switch ($e->getCode()) {    
                case 0 : $error = "Unspecified error.";
                    break;    
                case 1 : $error = "Hybriauth configuration error.";
                    break;    
                case 2 : $error = "Provider not properly configured.";
                    break;   
                case 3 : $error = "Unknown or disabled provider.";
                    break;    
                case 4 : $error = "Missing provider application credentials.";
                    break;    
                case 5 : $error = "Authentication failed. ";
                         $error .= "The user has canceled the authentication ";
                         $error .= "or the provider refused the connection.";
                    break;    
                case 6 : $error = "User profile request failed. ";   
                         $error .= "Most likely the user is not connected to the ";
                         $error .= "provider and he should to authenticate again.";
                    $adapter->logout();    
                    break;    
                case 7 : $error = "User not connected to the provider.";    
                    $adapter->logout();    
                    break;
            }            
           $error .= "<br /><br /><b>Original error message:</b> " . $e->getMessage();    
           $error .= "<hr /><pre>Trace:<br />" . $e->getTraceAsString() . "</pre>";
        }    
    endif;
    ?>
    <div class="page-header">
        <h2>
         Import Contacts
        </h2>
      </div>
    <div>    
    <?php

    if ($error) {    
        echo '<p><h3 style="color:red">Error!</h3>' . $error . '</p>';    
        echo "<pre>Session:<br />" . print_r($_SESSION, true) . "</pre><hr />";
    }
    ?>    
    <div class="inviteFriends">
         <table width="500" border="0" cellpadding="2" cellspacing="2">    
               <tr>     
                   <td align="left" valign="top">     
                       <fieldset>    
                           <legend>Sign-in with one of these providers</legend>    
                                <a class="socialIcon" href="?provider=Facebook"><img src="<?php echo $this->baseUrl() ?>/images/fb.png" width="181" height="60" border="0" alt="" /></a>        
                                <a class="socialIcon" href="?provider=Google"> <img src="<?php echo $this->baseUrl() ?>/images/gmail.png" width="181" height="60" border="0" alt="" /> </a>    
                                <a class="socialIcon" href="?provider=Twitter"><img src="<?php echo $this->baseUrl() ?>/images/tw.png" width="181" height="60" border="0" alt="" /></a>                 
                                <a class="socialIcon" href="?provider=LinkedIn"><img src="<?php echo $this->baseUrl() ?>/images/ln.png" width="181" height="60" border="0" alt="" /></a>     
                       </fieldset>         
                   </td>     
    <?php
    try {    
        $hybridauth = new Hybrid_Auth($config);            
        $connected_adapters_list = $hybridauth->getConnectedProviders();           

        if (count($connected_adapters_list)) {?>
     <?php
        }
    } catch (Exception $e) {

        echo "Ooophs, we got an error: " . $e->getMessage();            
        echo " Error code: " . $e->getCode();            
        echo "<br /><br />Please try again.";            
        echo "<hr /><h3>Trace</h3> <pre>" . $e->getTraceAsString() . "</pre>";
    }
    ?>     
               </tr>     
         </table>
    </div>        
    </div>

我的联系人名单

您可以使用open inviter库:

open inviter是一个用于导入联系人的免费库


OpenInviterTM是完全免费的开源解决方案

我已经编辑了我的问题,现在您可以使用我的importContacts文件的代码。它支持PHP和几个地址簿,包括Gmail、Outlook、雅虎、AOL、Linkedin和Facebook(这一个是beta版)。
    <?php
        $config = 'hybridauth/hybridauth/config.php';

        require_once( "hybridauth/hybridauth/Hybrid/Auth.php" );
        $hybridauth = new Hybrid_Auth($config);
        $provider = @ trim(strip_tags($_GET["provider"]));
        if (!$hybridauth->isConnectedWith($provider)) {
         header("Location: importContacts?error=Your are not connected to $provider or your  session has expired");
        }
        ?>
        <script type="text/javascript">
       function frmChk() {
                var str = '';
        //     $('#frmContacts').submit(function(){
                $('input[id ^="chk_"]').each(function() {
                    var id = parseInt(this.id.replace('chk_', ''));
                    if ($('#chk_' + id).is(':checked')) {
                        str += (str.length == 0) ? id : ',' + id;
                    }
                });
        //        alert(str);
                $('#cnt_contacts').val(str);
        //        return false;
        //        });
                if (str.length > 0) {
                    return true;
                } else {
                    return false;
                }
            }
        </script>
        <form name="frmContacts" id="frmContacts" method="post"
action="inviteContacts" onsubmit="return frmChk();" >
            <table width="90%" border="0" cellpadding="2" cellspacing="2">
               <tr>
                    <td valign="top">

        <?php echo $this->render('menu.phtml'); ?>
                        <fieldset>
                            <legend>My Contact list</legend>
                            <table width="100%">

        <?php
        try {
            $adapter = $hybridauth->getAdapter($provider);
            $user_contacts = $adapter->getUserContacts();
            $i_c = 1;
            foreach ($user_contacts as $item) {
                ?>
                                       <tr> 
                                            <td>
<input type="checkbox" name="chk_<?php echo $i_c ?>" id="chk_<?php echo $i_c ?>" value="<?php echo $item->identifier; ?>" />
                   </td>
                 <td align="left" valign="top" width="55" >  
                <?php
                if ($item->photoURL) {
                    ?>
               <a href="<?php echo $item->profileURL; ?>"><img src="<?php echo $item->photoURL; ?>" border="0" width="48" height="48"></a>
                                                    <?php
                                                } else {
                                                    ?> 

       <img src="../images/avatar.png" width="48" height="48" >
                    <?php
                }
                ?>      </td>
                 <td align="left">  
               <a href="<?php echo $item->profileURL; ?>"><b>
        <?php echo $item->displayName; ?></b></a>
<small>(ID:<?php echo $item->identifier; ?>)</small>
      <br /><?php echo $item->description; ?>
      <br /><small><?php echo $item->profileURL; ?></small>
                   <br /><hr />
                 </td>
            </tr> 
                <?php
                $i_c++;
            }
            if (!count($user_contacts)) {
                echo "No contact found!";
            }
        } catch (Exception $e) {
             if ($e->getCode() == 8) {        
               echo "Provider does not support this feature. Currently only <b>";
               echo "Facebook, MySpace, Twitter and LinkedIn</b> do support this!"; 
               echo "<br />Please refer to the user guide to know more";    
               echo "about each adapters capabilities.";
               echo "<a href='http://hybridauth.sourceforge.net/userguide.html'>";
               echo "http://hybridauth.sourceforge.net/userguide.html</a>";
            } else {

                echo "Well, got an error: " . $e->getMessage();
            }
        }
        ?>                   </table>
                        </fieldset> 
                    </td>
                    <td valign="top" width="250" align="left"> 
                    </td>
                </tr>
                <tr>
      <td colspan="2"><input type="submit" value="Invite" name="btnInvite" /> </td>
                </tr>
                    </table>
            <input type="hidden" name="cnt_contacts" id="cnt_contacts" value="" />
        </form>