簡體   English   中英

Facebook App Uncaught OAuthException:必須使用活動訪問令牌來查詢有關當前用戶的信息。 拋出

[英]Facebook App Uncaught OAuthException: An active access token must be used to query information about the current user. thrown

您好,我試圖發布到用戶的牆上,但是會發生以下錯誤:未捕獲的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);

我如何獲得用戶訪問令牌?

在瀏覽器中打開它:

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]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM