0

我收到以下錯誤致命錯誤:在上線1039 base_facebook.php

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

我的框架應用程序包括兩個頁面 - index.phpindex1.php。默認情況下,當index.php負載,它已在頂部下面的鏈接繼續index1.php

<a href="index1.php">index1</a> 

而且下面的代碼:

<?PHP 
include("facebook.php"); 
$config = array(); 
$config['appId'] =$appId; 
$config['secret'] = $appSecret; 
$fb = new Facebook($config); 
$access_token = $fb->getAccessToken(); 
$user_profile = $fb->api('/me','GET'); 
$userid = $fb->getUser(); 
?> 

index1.php具有作爲的index.php是具有頂部相同的代碼。

當我加載應用程序它不給任何錯誤和負荷完美,但是當我在鏈接點擊index1.php它給

Uncaught OAuthException: An active access token must be used to query information about the current user in base_facebook.php at 1039

我該如何解決這個問題?

回答

2

您可能沒有活動的訪問令牌。爲了得到一個,用戶必須授權您的應用程序和登錄您可以嘗試var_dump($access_token) - 我懷疑你會發現它返回nullfalse

你可以嘗試像

if(($access_token = $fb->getAccessToken()) && ($userid = $fb->getUser())) { 
    $user_profile = $fb->api('/me','GET'); 
}