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'); 
}