您好我正在尝试使用应用会话发出请求并且说:"(#200)必须有一个有效的access_token来访问此端点" 。我只能通过应用会话提出请求吗?
在代码下面给我这个错误。
<?php
require_once( 'Facebook/FacebookSession.php' );
require_once( 'Facebook/GraphObject.php' );
require_once( 'Facebook/GraphSessionInfo.php' );
require_once( 'Facebook/FacebookRedirectLoginHelper.php' );
require_once( 'Facebook/FacebookSDKException.php' );
require_once( 'Facebook/FacebookRequestException.php' );
require_once( 'Facebook/FacebookPermissionException.php');
require_once( 'Facebook/FacebookRequest.php' );
require_once( 'Facebook/FacebookResponse.php' );
require_once( 'Facebook/FacebookAuthorizationException.php' );
require_once( 'Facebook/GraphObject.php' );
require_once( 'Facebook/Entities/AccessToken.php' );
require_once( 'Facebook/HttpClients/FacebookCurl.php');
require_once( 'Facebook/HttpClients/FacebookHttpable.php');
require_once( 'Facebook/HttpClients/FacebookCurlHttpClient.php');
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
// start session
session_start();
// init app with app id and secret
FacebookSession::setDefaultApplication( $facebook_app_id, $facebook_app_secret);
$session = FacebookSession::newAppSession();
// To validate the session:
try {
$session->validate();
} catch (FacebookRequestException $ex) {
// Session not valid, Graph API returned an exception with the reason.
echo $ex->getMessage();
} catch (\Exception $ex) {
// Graph API returned info, but it may mismatch the current app or have expired.
echo $ex->getMessage();
}
if(isset($session)){
try {
$response = (new FacebookRequest($session, 'GET', '/search?q=coimbra&type=event&limit=5000'))->execute();
$object = $response->getGraphObject();
echo "done.";
} catch (FacebookRequestException $ex) {
echo $ex->getMessage();
} catch (\Exception $ex) {
echo $ex->getMessage();
}
}
?>
答案 0 :(得分:0)
错误表示您必须拥有有效的USER access_token
才能进行搜索。这是因为搜索结果将过滤掉用户不允许查看的事件(或其他内容),例如,私人活动或非公开活动。但这也意味着您找到了用户有权查看的事件。
总之,您需要将用户登录以获取有效的用户access_token
,以使搜索生效。