2014-05-05 14 views
5

Web sitem için en son php sürümünü (facebook-php-sdk-v4) kullanarak bir giriş facebook seçeneğine sahip olmaya çalışıyorum ama sadece (FacebookSession.php) Ben uygulamak çalışıyorum PHP SDK V4 sürümü parçasıdırFacebook hesabını kullanarak giriş yapma (facebook-php-sdk-v4)

Parse error: syntax error, unexpected T_OBJECT_OPERATOR in 
/home/.../src/Facebook/FacebookSession.php on line 89 

Ve bu kodu bilmelidir olarak: tarayıcı tarafından bu hatayı almaya devam. (https://developers.facebook.com/docs/php/gettingstarted/4.0.0)

Bu hata bildirir dosyanın bir parçasıdır (Ben bile senaryoya dahil ettik ama aynı sonucu elde):

$me = (new FacebookRequest(
$session, 'GET', '/me' 
))->execute()->getGraphObject(GraphUser::className()); 

Bu benim koydum tam koddur web sitemin index.php:

<?php 

require_once('src/Facebook/FacebookSession.php'); 
require_once('src/Facebook/FacebookRedirectLoginHelper.php'); 
require_once('src/Facebook/FacebookRequest.php'); 
require_once('src/Facebook/FacebookResponse.php'); 
require_once('src/Facebook/FacebookSDKException.php'); 
require_once('src/Facebook/FacebookRequestException.php'); 
require_once('src/Facebook/FacebookAuthorizationException.php'); 
require_once('src/Facebook/GraphObject.php'); 

use src\Facebook\FacebookSession; 
use src\Facebook\FacebookRedirectLoginHelper; 
use src\Facebook\FacebookRequest; 
use src\Facebook\FacebookResponse; 
use src\Facebook\FacebookSDKException; 
use src\Facebook\FacebookRequestException; 
use src\Facebook\FacebookAuthorizationException; 
use src\Facebook\GraphObject; 

// start session 
session_start(); 

// init app with app id and secret 
FacebookSession::setDefaultApplication('xxxxxxxxxxxx','xxxxxxxxxxxxxxxxxxxxxxxxxxx'); 

$helper = new FacebookRedirectLoginHelper('your redirect URL here'); 
$loginUrl = $helper->getLoginUrl(); 
// Use the login url on a link or button to redirect to Facebook for authentication 

$helper = new FacebookRedirectLoginHelper(); 
try { 
$session = $helper->getSessionFromRedirect(); 
} catch(FacebookRequestException $ex) { 
// When Facebook returns an error 
} catch(\Exception $ex) { 
// When validation fails or other local issues 
} 
if ($session) { 
// Logged in 
} 
?> 

Herhangi bir rehberlik büyük takdir edilecektir.

cevap

5

(PHP < 5.4.0) Facebook SDK 4.0 To Run

böyle FacebookSession.php Örnek olarak tüm facebook sayfasından yöntemini zincirleme değiştirmek zincirleme yöntemi değiştirdikten sonra

// change this 
$graphObject = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(); 

// into this 
$request = new FacebookRequest($session, 'GET', '/me'); 
$response = $request->execute(); 
$graphObject = $response->getGraphObject(); 

altındadır Lütfen Lütfen de değişti.

// change this 
if (session_status() !== PHP_SESSION_ACTIVE) { 
     throw new FacebookSDKException(
     'Session not active, could not load state.' 
    ); 
    } 

// into this 
if(session_id() === "") { 
    throw new FacebookSDKException(
     'Session not active, could not load state.' 
    ); 
} 
3

hatası: SDK v4 PHP sürüm 5.4

gerektirdiğinden “Ayrıştırma hatası sözdizimi hatası, içinde ... beklenmedik T_OBJECT_OPERATOR” dir
İlgili konular