php 必须使用主动访问令牌来查询有关当前用户图 api 异常的信息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11776234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
An active access token must be used to query information about the current user-Graph api exception
提问by my name is xyz
I am trying to update Facebook user status using Graph api. My code is
我正在尝试使用 Graph api 更新 Facebook 用户状态。我的代码是
<?php
require 'facebook.php';
$facebook = new Facebook(array(
'appId' =>'389694921095423',
'secret' =>'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
'cookie' => true
));
$access_token = $facebook->getAccessToken();
echo($access_token);
$me = null;
try
{
$uid = $facebook->getUser();
$me = $facebook->api('/me');
echo "Welcome User: " . $me['name'] . "<br />";
//access permission
$permissions_needed = array('publish_stream', 'read_stream', 'offline_access', 'manage_pages');
foreach($permissions_needed as $perm)
{
if( !isset($permissions_list['data'][0][$perm]) || $permissions_list['data'][0][$perm] != 1 )
{
$login_url_params = array(
'scope' => 'publish_stream,read_stream,offline_access,manage_pages',
'fbconnect' => 1,
'display' => "page",
'next' => 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']
);
$login_url = $facebook->getLoginUrl($login_url_params);
header("Location: {$login_url}");
exit();
}
}
//Access permission
$post_id = $facebook->api("/$uid/feed", "post", array("message"=>"Hello World!"));
if(isset($post_id))
{
echo "A new post to your wall has been posted with id: $post_id";
}
}
catch (FacebookApiException $e)
{
echo($e);
}
?>
The problem is that it shows a run time error like Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. I have generated the Access Tocken. Where i have to use that to remove this exception Thanks in advance
问题是它显示了一个运行时错误,如 Fatal error: Uncaught OAuthException: An active access token must be used to query about the current user. 我已经生成了访问令牌。我必须在哪里使用它来删除此异常 提前致谢
回答by happyhardik
Try changing the line:
尝试更改行:
$me = $facebook->api('/me');
to
到
$me = $facebook->api('/'.$uid);
Also try upgrading your sdk if you are not using the latest version and if you just upgraded the sdk and it caused the trouble, than you can try to downgrade the version and check.
如果您没有使用最新版本,并且您刚刚升级了 sdk 并且导致了问题,也可以尝试升级您的 sdk,然后您可以尝试降级版本并检查。
回答by Mudaser Ali
Clear your cache & cookies (if you are testing or developing application) and Please do as follow:-
清除您的缓存和 cookie(如果您正在测试或开发应用程序),请执行以下操作:-
try
{
$fb_user_info = $facebook->api('/me');
} catch (Exception $ex)
{
$facebook->destroySession();
$params = array(
'scope' => 'YOUR_PERMISSIONS',
'redirect_uri' => 'YOUR_SITE_URL'
);
$fb_login_url = $facebook->getLoginUrl($params);
header("Location:" . $fb_login_url);
}

