这是我的许可代码:
$permissions = $facebook->api("/me/permissions");
if( @array_key_exists('publish_stream', $permissions['data'][0]) ) {
// Permission is granted!
// Do the related task
} else {
// We don't have the permission
// Alert the user or ask for the permission!
echo '<script>
window.location.replace("facebook.com/dialog/oauth?client_id=257378464344747&redirect_uri=https://www.facebook.com/pages/Test-Matyii/399406486739482?sk=app_257378464344747&scope=email,publish_stream");
</script>' ;
}
但我有错误:
Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in /app/www/sdk/src/base_facebook.php on line 1106
答案 0 :(得分:0)
您需要确保正确设置PHP SDK,例如
$facebook = new Facebook(array(
'appId' => 'APP_ID',
'secret' => 'APP_SECRET',
));
$user = $facebook->getUser();
if ($user) {
try {
$permissions = $facebook->api("/me/permissions");
// do something with the perms
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
如果$ user在这里有效,则会记录用户并且对api的调用应该有效,但是如果它为null,则需要让用户登录getLoginUrl