0

我只是想使用 PHP 将图像上传到用户的时间轴。安装我的应用程序后,我使用以下代码但收到错误: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>";
}

?>
4

1 回答 1

1

您可能有一个无效或过期的访问令牌,请查看处理无效和过期的访问令牌。在api调用之前和$token声明之后插入本文提供的代码。

于 2012-05-12T08:58:36.370 回答