开发者

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

开发者 https://www.devze.com 2023-04-09 08:46 出处:网络
Hello I amtrying to post to the wall of a user but the following error occurs: Uncaught OAuthExce开发者_如何学编程ption: An active access token must be used to query information about the current user

Hello I am trying to post to the wall of a user but the following error occurs: Uncaught OAuthExce开发者_如何学编程ption: An active access token must be used to query information about the current user. thrown ....

My facebook script is:

$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);

How can i obtain users access token?


Open this in a browser:

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

You’ll be redirected to:

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

And you have your access token, you can go ahead and use it:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号