問題描述
我正在嘗試使用 Graph api 更新 Facebook 用戶狀態.我的代碼是
I am trying to update Facebook user status using Graph api. My code is
<?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);
}
?>
問題是它顯示了一個運行時錯誤,如致命錯誤:未捕獲的 OAuthException:必須使用活動訪問令牌來查詢有關當前用戶的信息.我已經生成了訪問令牌.我必須使用它來刪除此異常的地方提前致謝
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
推薦答案
換行試試:
$me = $facebook->api('/me');
到
$me = $facebook->api('/'.$uid);
如果您使用的不是最新版本,也可以嘗試升級您的 sdk,如果您剛剛升級了 sdk 并導致了問題,那么您可以嘗試降級版本并檢查.
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.
這篇關于必須使用主動訪問令牌來查詢有關當前 user-Graph api 異常的信息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!