[英]facebook Uncaught OAuthException: An active access token must be used to query information about the current user
[英]Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user
我有一個Facebook應用程序,無論我嘗試了什么,它似乎都無法正常工作。 我得到錯誤:
致命錯誤:未被捕獲的OAuthException:必須使用活動訪問令牌來查詢有關當前用戶的信息。 在第1024行上../src/base_facebook.php中拋出
這是代碼:
<?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()之前。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.