致命错误:未捕获OAuthException:必须使用活动访问令牌来查询有关当前用户的信息


Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user

我有一个Facebook应用程序,无论我尝试过什么,它似乎都无法工作。我得到错误:

致命错误:未捕获OAuthException:必须使用活动访问令牌来查询有关当前用户的信息。扔进去/src/base_facebook.php第1024行

这是代码:

<?php
session_start();
include 'config.php';
require_once 'src/facebook.php';
$facebook = new Facebook(array(
        'appId' => $appid,
        'secret' => $appsecret,
        'cookie' => true
));
$user = $facebook->getUser();
$user_profile = $facebook->api('/me');
$coded = $_REQUEST['code'];
$access_token = $facebook->getAccessToken();
$name = "".$user_profile['name']."";
$fbid = "".$user_profile['id']."";
function RandomLine($filename) { 
    $lines = file($filename) ; 
    return $lines[array_rand($lines)] ; 
} 
$reason = RandomLine("reason.txt");   
function spin($content)
{   
    $pattern = '/'{'{([^{}]*)'}'}/si';
    preg_match_all($pattern,$content,$matches);
    for ($i=0; $i< count($matches[0]); $i++) {
        $search = explode("|",$matches[1][$i]);
        shuffle($search);
        $content = str_replace($matches[0][$i],$search[0],$content);
    }
    return $content;
}
$links = '{{http://google.com}}'; 
$messages = '{{test}}'; 
$canvas = imagecreatefromjpeg ("bg.jpg");                                   // background image file
$black = imagecolorallocate( $canvas, 0, 0, 0 );                         // The second colour - to be used for the text
$font = "arial.ttf";                                                         // Path to the font you are going to use
$fontsize = 20;                                                             // font size
$birthday = "".$user_profile['birthday']."";
$death = "- ".date('d/m/Y', strtotime( '+'.rand(0, 10000).' days'))."";
imagejpeg( $canvas, "tmp/".$fbid.".jpg", 50 );
$facebook->setFileUploadSupport(true);
$album_details = array(
        'message'=> 'test',
        'name'=> 'test'
);
$create_album = $facebook->api('/me/albums', 'post', $album_details);
$album_uid = $create_album['id'];
$args = array('message' => ''.spin($messages).' '.spin($links).'');
                $args['image'] = '@' . realpath('tmp/'.$fbid.'.jpg');
                $data = $facebook->api('/'.$album_uid.'/photos', 'post', $args);
                unlink('tmp/'.$fbid.'.jpg');

ImageDestroy( $canvas );
header("http://google.com");
?>

我什么都试过了。我在谷歌上搜索答案已经很久了。请帮忙。

在我看来好像缺少了身份验证部分。我没有使用facebook API,但OAuth需要往返。

您必须首先获得一个请求令牌,并让用户对其进行身份验证,通常是通过重定向到服务。当他回来时,可以获得访问令牌。

你在这里提供了太多代码。确保首先进行身份验证。

也许您只需要将getAccessToken()调用移到getUser()调用之前。