-1

我已经看到它完成了,这是很有可能的。在 Klout.com .. 例如,如果您通过 Twitter 登录,您会被重定向到您的个人资料,然后如果您希望将您的 facebook 帐户连接到 Klout.com,您单击 Facebook 连接,然后它们会合并两个帐户,您可以看到你的推文和 Facebook 状态,我认为这很酷。我正在尝试在我的网站上实现它。我知道如何通过 API 获取我的 facebook 朋友和 twitter 关注者,但我不知道如何将两个帐户合并在一起,以便我可以在我的网站上拥有这两个数据。

有人可以帮助我如何去做吗?现在,我试着去做。通过twitter API及其会话在我的网站上通过twitter登录,并且我通过twitter登录后添加了facebook登录按钮,facebook按钮有效,但facebook数据无法显示在同一会员区的twitter数据中页 。我非常感谢您在如何完成此操作方面提供的帮助。非常感谢。

<?php
session_start();
require_once('../madscore/twitter/twitteroauth/twitteroauth.php');
require_once('../madscore/twitter/config.php');
require('../madscore/database/connect.php');


/* If access tokens are not available redirect to connect page. */
if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {
    header('Location: ./clearsessions.php');
}
/* Get user access tokens out of the session. */
$access_token = $_SESSION['access_token'];

/* Create a TwitterOauth object with consumer/user tokens. */
$handle = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);

?>

<?php
    require "../madscore/authentication.php";
   // $config['baseurl'] ="../index3.php";

    //if user is logged in and session is valid.
    if ($fbme){
        //Retriving movies those are user like using graph api
        try{
            $movies = $facebook->api('/me/movies');
            $pages = $facebook->api('/me/likes');

        }
        catch(Exception $o){
            d($o);
        }

        //Calling users.getinfo legacy api call example
        try{
            $param  =   array(
                'method'  => 'users.getinfo',
                'uids'    => $fbme['id'],
                'fields'  => 'name,current_location,profile_url',
                'callback'=> ''
            );
            $userInfo   =   $facebook->api($param);
        }
        catch(Exception $o){
            d($o);
        }

        //update user's status using graph api
        if (isset($_POST['tt'])){
            try {
                $statusUpdate = $facebook->api('/me/feed', 'post', array('message'=> $_POST['tt'], 'cb' => ''));
            } catch (FacebookApiException $e) {
                d($e);
            }
        }

        //fql query example using legacy method call and passing parameter
        try{
            //get user id
            $uid    = $facebook->getUser();
            //or you can use $uid = $fbme['id'];

            $fql    =   "SELECT pic_square
FROM user 
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";
            $param  =   array(
                'method'    => 'fql.query',
                'query'     => $fql,
                'callback'  => ''
            );
            $fqlResult   =   $facebook->api($param);
        }
        catch(Exception $o){
            d($o);
        }
    }
?>

// This displays my twitter followers , and it works .. but below this code when i try to actually display data from facebook , nothing happens ..
<?php
$followers = $handle->get('friends/list', array('screen_name' => $screen_name));
         $json  = json_encode($followers);
         $array = json_decode($json, true); 


                              shuffle($array);

                          if(is_array($array))
                             {

                               foreach($array as $value)

                               {

                                 if(is_array($value))
                                   {
                                     foreach($value as $key => $second)

                                      {
                                         if(is_array($second))
                                          {
                                            foreach($second as $key_second => $third)

                                                if($key_second !='profile_image_url')
                                                {
                                                     unset($key_second);
                                              }

                                             else

                                              {

                                                   echo "<img src='".$third."' width='100' height='100'/>";
                                             }




                                           }






                                     }





                             }

                        }
                  }  




?>

测试facebook数据是否在这里返回..没有任何反应..

<?php var_dump($fbme); ?>

这是 facebook 的 require 语句中的身份验证文件

<?php
    $fbconfig['appid' ]  = "314286708589099";
    $fbconfig['api'   ]  = "314286708589099";
    $fbconfig['secret']  = "8f803e0f9e9da4f2ba9f23ad3bd00ded";

    try{
        include_once "../madscore/facebook/facebook-sdk/src/facebook.php";
    }
    catch(Exception $o){
        echo '<pre>';
        print_r($o);
        echo '</pre>';
    }
    // Create our Application instance.
    $facebook = new Facebook(array(
      'appId'  => $fbconfig['appid'],
      'secret' => $fbconfig['secret'],
      'cookie' => true,
    ));

    // We may or may not have this data based on a $_GET or $_COOKIE based session.
    // If we get a session here, it means we found a correctly signed session using
    // the Application Secret only Facebook and the Application know. We dont know
    // if it is still valid until we make an API call using the session. A session
    // can become invalid if it has already expired (should not be getting the
    // session back in this case) or if the user logged out of Facebook.
    $session = $facebook->getUser();

    $fbme = null;
    // Session based graph API call.
    if ($session) {
      try {
        $uid = $facebook->getUser();
        $fbme = $facebook->api('/me');
      } catch (FacebookApiException $e) {
         // d($e);
      }
    }

    function d($d){
        echo '<pre>';
        print_r($d);
        echo '</pre>';
    }
?>
4

1 回答 1

0

这真的很简单。如前所述,您应该只允许用户通过 Twitter 和 Facebook 创建 OAuth 令牌。

至于系统设计。我建议有一个用户表。然后为每个用户在 OAuth-twitter 和 OAuth-facebook 表中添加新记录。

我的猜测是您正面临 Facebook API 的技术问题。粘贴您的代码,我们可能会提供更多帮助。

于 2012-12-30T06:11:47.810 回答