我只是試圖使用PHP將圖像上傳到用戶的時間軸。安裝我的應用程序後,我使用以下代碼,但得到錯誤:OAuthException:必須使用活動訪問令牌來查詢有關當前用戶的信息。使用PHP將圖片上傳到Facebook時出錯:OAuthException:必須使用有效的訪問令牌來查詢有關當前用戶的信息。
我能夠通過$ token變量回顯訪問令牌,所以我知道它在那裏。我到處尋找,並試圖解決它,但沒有成功。繼承人的代碼...
<?php
include_once "src/facebook.php";
$app_id = 'xxxxxx';
$application_secret = 'xxxxxx';
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $application_secret,
'cookie' => true, // enable optional cookie support
));
if ($facebook->getUser())
{
$user = $facebook->getUser();
//die($token);
try
{
$token = $facebook->getAccessToken();
$facebook->setFileUploadSupport(true);
$file = "5star.png";
$post_data = array(
"message" => "My photo caption",
"source" => '@' . realpath($file)
);
//die("/me/photos/?access_token=$token");
$data['photo'] = $facebook->api("/me/photos?access_token=$token", 'post', $post_data);
} catch (FacebookApiException $e)
{
die($e);
}
header('Location: http://google.com') ;
}else
{
$loginUrl = "https://graph.facebook.com/oauth/authorize?type=user_agent&display=page&client_id=$app_id&redirect_uri=http://apps.facebook.com/yourprofilerating/&scope=user_photos,email,offline_access,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown";
echo "<script> top.location.href='" . $loginUrl . "'</script>";
}
?>
http://stackoverflow.com/questions/6034813/facebook-uncaught-oauthexception-an-active-access-token-must-be-used-to-query-i –