【问题标题】:Facebook App Uncaught OAuthException: An active access token must be used to query information about the current user. thrownFacebook App Uncaught OAuthException:必须使用活动访问令牌来查询有关当前用户的信息。抛出
【发布时间】:2011-11-26 08:41:07
【问题描述】:

您好,我正在尝试发布到用户的墙上,但出现以下错误: 未捕获的 OAuthException:必须使用活动访问令牌来查询有关当前用户的信息。扔了....

我的 Facebook 脚本是:

$appId = 'xxxxxx'; //change as necessary
$appUrl = "xxxxx";  //change as necessary
$baseUrl = "xxxxx/";   //change as necessary
// Create our Application instance.
$facebook = new Facebook(array(
  'appId'  => $appId,
  'secret' => 'xxxxxx', //change as necessary
  'cookie' => true,
));
$session = $facebook->getSession();
$fbme = null;
// Session based graph API call.
if (!$session)
{
  $login_url = $facebook->getLoginUrl
    (
    array
      (
        "canvas" => true,
        "fbconnect" => false,
        "req_perms" => "user_location, email, publish_stream, friends_about_me, offline_access,",
      )
   );
   echo "<script type='text/javascript'>top.location.href = '" . $login_url. "';</script>";
}
$session = $facebook->getSession();
$me = null;
// Session based API call.
if ($session) {
 try {
   $uid = $facebook->getUser();
   $me = $facebook->api('/me');
   $mail=$me[email];
  } catch (FacebookApiException $e) {
    error_log($e);
  }

}

$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2); 
    $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
    $token=$data[oauth_token];
    $attachment = array('message' => '',
       'access_token' =>$token,
       'name' => '',
       'caption' => "",
       'link' => '',
       'description' => '',
       'picture' => '',
       'actions' => array(array('name' => 'Get Social',
                                        'link' => ''))
     );


$result = $facebook->api('me/feed','post',$attachment);

如何获取用户访问令牌?

【问题讨论】:

    标签: php facebook token


    【解决方案1】:

    在浏览器中打开:

    https://graph.facebook.com/oauth/authorize?
        type=user_agent&
        client_id=[APP ID]&
        redirect_uri=http%3A%2F%2Fxyz.com&
        scope=user_photos,email,user_birthday,user_online_presence
    

    您将被重定向到:

    http://xyz.com/#access_token=[ACCESS TOKEN].
    

    你有你的访问令牌,你可以继续使用它:

    https://graph.facebook.com/me?access_token=
        [ACCESS TOKEN]
    

    【讨论】:

      猜你喜欢
      • 2011-08-27
      • 2013-07-22
      • 2012-01-23
      • 1970-01-01
      • 1970-01-01
      • 2014-04-12
      • 1970-01-01
      • 1970-01-01
      • 2013-03-14
      相关资源
      最近更新 更多