我想讓Facebook登錄與他們的新的PHP SDK 4.0爲我的網站工作。我幾乎一字不差地遵循了他們的要求,甚至連測試頁也無法工作。當我嘗試登錄時,我重定向到格式的URL:Facebook的PHP SDK 4.0登錄
https://www.facebook.com/v2.0/dialog/oauth?client_id={some number}&redirect_uri{localhost%2F%7E{MyName}%2F{my site}}&state=08d94ec4670256aa2b2c586781590766&sdk=php-sdk-4.0.0&scope=
我已經填寫了相同的URL我的Facebook開發者頁面上已經,這是我想測試代碼:
<?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');
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('{My app ID}','{My app secret}');
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper('localhost/~{My Name}/{My Project}');
try {
$session = $helper->getSessionFromRedirect();
} catch(FacebookRequestException $ex) {
// When Facebook returns an error
} catch(Exception $ex) {
// When validation fails or other local issues
}
// see if we have a session
if (isset($session)) {
// graph api request for user data
$request = new FacebookRequest($session, 'GET', '/me');
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject();
// print data
echo '<pre>' . print_r($graphObject, 1) . '</pre>';
} else {
// show login url
echo '<a href="' . $helper->getLoginUrl() . '">Login</a>';
}
不幸的是,我從來沒有被重定向回去,甚至沒有加載登錄頁面。我在這裏做錯了什麼?