2

我正在使用 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>

这是查找联系人代码

    <?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>
4

1 回答 1

0

您可以使用开放的邀请者库:

http://openinviter.com/download.php

开放式邀请者是一个免费的图书馆,用于导入联系人。

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

于 2014-09-12T16:20:11.557 回答