gpt4 book ai didi

php - 找不到类 'FacebookSession' - API Facebook 4.0

转载 作者:搜寻专家 更新时间:2023-10-31 20:40:15 25 4
gpt4 key购买 nike

我正在尝试新的 Facebook API (4.0),但我遇到了严重的问题。

我的页面loginUser.php的代码是:

<?php
require_once("autoload_fb.php");


// init app with app id and secret
FacebookSession::setDefaultApplication( '647345538685342','6ea4dc94874b31a637b6fe368bcfba76' );

// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper( 'http://www.radiobrunoestate.mumbleserver.it/api/loginUser' );

// see if a existing session exists
if ( isset( $_SESSION ) && isset( $_SESSION['fb_token'] ) ) {
// create new session from saved access_token
$session = new FacebookSession( $_SESSION['fb_token'] );

// validate the access_token to make sure it's still valid
try {
if ( !$session->validate() ) {
$session = null;
}
} catch ( Exception $e ) {
// catch any exceptions
$session = null;
}

} else {
// no session exists

try {
$session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
// When Facebook returns an error
} catch( Exception $ex ) {
// When validation fails or other local issues
echo $ex->message;
}

}

// see if we have a session
if ( isset( $session ) ) {

// save the session
$_SESSION['fb_token'] = $session->getToken();
// create a session using saved token or the new one we generated at login
$session = new FacebookSession( $session->getToken() );

// graph api request for user data
$request = new FacebookRequest( $session, 'GET', '/me' );
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject()->asArray();

// print profile data
echo '<pre>' . print_r( $graphObject, 1 ) . '</pre>';

// print logout url using session and redirect_uri (logout.php page should destroy the session)
echo '<a href="' . $helper->getLogoutUrl( $session, 'http://yourwebsite.com/app/logout.php' ) . '">Logout</a>';

} else {
// show login url
echo '<a href="' . $helper->getLoginUrl( array( 'email', 'user_friends' ) ) . '">Login</a>';
}
?>

autoload_fb.php 很简单:

<?php
session_start();

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

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

我在第一台服务器上收到此错误:

Fatal error: Class 'FacebookSession' not found in /home/jack/provaprova/api/loginUser.php on line 6

在另一台服务器上测试相同的代码我有这个错误:

Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /home/eyikmdnu/public_html/jack/provaprova/api/Facebook/FacebookSession.php on line 140

问题出在哪里?可能是服务器配置的问题?

谢谢

最佳答案

Facebook PHP SDK v4 需要 PHP 5.4。您很可能使用的是旧版本的 PHP。

关于php - 找不到类 'FacebookSession' - API Facebook 4.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23789989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com