从Facebook页面获取页面供稿

时间:2014-07-31 19:12:00

标签: php facebook facebook-graph-api facebook-php-sdk

我正在使用facebook api从Facebook页面获取提要。 这是我正在使用的代码:

session_start(); 
require_once( 'Facebook/FacebookSession.php' );
require_once( 'Facebook/FacebookRedirectLoginHelper.php' );
require_once( 'Facebook/FacebookRequest.php' );
require_once ('Facebook/GraphObject.php' );
require_once ('Facebook/GraphSessionInfo.php' );

require_once( 'Facebook/Entities/AccessToken.php' );
require_once( 'Facebook/FacebookResponse.php' );
require_once( 'Facebook/FacebookSDKException.php' );
require_once( 'Facebook/FacebookRequestException.php' );
require_once( 'Facebook/FacebookAuthorizationException.php' );
require_once( 'Facebook/GraphObject.php' );
require_once('Facebook/HttpClients/FacebookHttpable.php');
require_once( 'Facebook/HttpClients/FacebookCurl.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;

FacebookSession::setDefaultApplication('app_id', 'app_secret');
$session = new FacebookSession('access_token');
$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();
}

$request = new FacebookRequest(
  $session,
  'GET',
  '/{page-id}/feed'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();

我在代码中添加了app_id,app_secret,page-id和access_token。但是我收到了错误

Fatal error: Uncaught exception 'Facebook\FacebookAuthorizationException' with message '(#803) Some of the aliases you requested do not exist: {page-id}

但是如果我打开https://graph.facebook.com/page-id?access_token=my_access_token,我会得到所需的数据。 我在localhost上做所有的事情。有人可以帮我找到错误吗?

0 个答案:

没有答案