此代码:
$clientid ='**************';
$secret = '********************';
//Include sdk classes
require_once( 'Facebook/FacebookHttpable.php' );
require_once( 'Facebook/FacebookSession.php' );
require_once( 'Facebook/FacebookRedirectLoginHelper.php' );
require_once( 'Facebook/FacebookRequest.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/FacebookCurlHttpClient.php' );
require_once( 'Facebook/FacebookCurl.php' );
require_once( 'Facebook/GraphUser.php' );
use Facebook\FacebookHttpable;
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\FacebookCurlHttpClient;
use Facebook\FacebookCurl;
use Facebook\GraphUser;
// init app with app id (APPID) and secret (SECRET)
FacebookSession::setDefaultApplication($clientid,$secret);
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper( $redirect );
try {
$session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
// When Facebook returns an error
} catch( Exception $ex ) {
// When validation fails or other local issues
}
$me = (new FacebookRequest(
$session, 'GET', '/me'
))->execute()->getGraphObject(GraphUser::className);
echo $me->getName();
抛出错误:
[2014年11月18日12:57:31 UTC] PHP解析错误:语法错误,意外的T_OBJECT_OPERATOR在.......第53行
第53行:
))->execute()->getGraphObject(GraphUser::className);
我从https://developers.facebook.com/docs/php/FacebookRequest/4.0.0复制并粘贴了该代码块 那怎么会出现解析错误?
PHP版本5.3
答案 0 :(得分:1)
此版本的Facebook SDK for PHP需要PHP 5.4或更高版本。