2012-02-22 91 views
2

我有一個Facebook應用程序,似乎無法正常工作,無論我嘗試了什麼。 我收到錯誤:致命錯誤:未捕獲OAuthException:必須使用活動訪問令牌來查詢有關當前用戶的信息

致命錯誤:未捕獲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"); 

?> 

我已經嘗試了一切。我一直在尋找答案的年齡。 請幫忙。

+0

期待對此做出迴應。這真的很痛苦... – pal4life 2012-03-21 20:52:01

回答

1

在我看來,認證部分丟失了。我沒有使用Facebook API,但OAuth需要往返。

您必須先獲取請求令牌並讓用戶對其進行身份驗證,通常通過重定向到服務。當他回來時,可以獲得訪問令牌。

你在這裏提供了太多的代碼。確保身份驗證首先工作。

也許你只需要在getUser()之前移動getAccessToken()調用即可。

相關問題