Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in C:\xampp\htdocs\fyp\plugin\facebook-sdk\src\base_facebook.php on line 1106
问题如上所述。我花了一些时间来搜索解决方案,但在修改代码后仍然无效。我注意到有一个网站可以获得一个
https://graph.facebook.com/oauth/authorize?
type=user_agent&
client_id=116122545078207&
redirect_uri=http%3A%2F%2Fxyz.com&
scope=user_photos,email,user_birthday,user_online_presence
我可以将它包含在我的脚本中吗?所以我不必每次都去这个网址
。如何将其包含在我的phpscript中以便解决问题?
感谢您提供任何帮助。
<?require 'plugin/facebook-sdk/src/facebook.php';
$session='123456';
$facebook = new Facebook(array(
'appId' => '1234567',
'secret' => '123456789',
'cookie' => true,
));
$me = null;
// Session based API call.
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
}
}
// login or logout url will be needed depending on current user state.
if ($me) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}
if ($session) {
// We have a valid FB session, so we can use 'me'
$result = $facebook->api('/me/feed','post',array('message' => 'testmessage'));
} elseif( isset($_SESSION['user_id']) ) {
$result = $facebook->api("/{$_SESSION['user_id']}/feed",'post',array('message' => 'testmessage'));
}
?>
答案 0 :(得分:1)
编辑范围,
scope=user_photos,email,user_birthday,user_online_presence,publish_stream
&安培;再次访问此链接
https://graph.facebook.com/oauth/authorize?
type=user_agent&
client_id=116122545078207&
redirect_uri=http%3A%2F%2Fxyz.com&
scope=user_photos,email,user_birthday,user_online_presence,publish_stream