0
我想爲v2.8圖形api製作一個登錄頁面。Facebook登錄php
我遵循所有圖api的例子,但仍然出現錯誤。
這是錯誤:
Facebook SDK returned an error: Cross-site request forgery validation failed. Required param "state" missing from persistent data.
fbaccess.php
session_start();
$app_id = "xxxxxx";
$app_secret = "xxxxx";
$site_url = "http://xxxxxxxxx/";
require_once __DIR__ . '/src/autoload.php';
// Create our application instance
$fb = new Facebook\Facebook([
'app_id' => $app_id,
'app_secret' => $app_secret,
'default_graph_version' => 'v2.8',
]);
的index.php
session_start();
include("fbaccess.php");
$helper = $fb->getRedirectLoginHelper();
$permissions = ['email', 'user_likes']; // optional
$loginUrl = $helper->getLoginUrl('http://shortbucks.com/facebook/callback.php', $permissions);
echo '<a href="' . $loginUrl . '">Log in with Facebook!</a>';
callback.php
session_start();
include("fbaccess.php");
$helper = $fb->getRedirectLoginHelper();
try {
// Returns a `Facebook\FacebookResponse` object
$accessToken = $helper->getAccessToken();
$response = $fb->get('/me?fields=id,name', $accessToken);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$user = $response->getGraphUser();
echo 'Name: ' . $user['name'];
有人能幫我找出錯誤嗎?
感謝
你可以找到關於這與谷歌的一些信息:https://開頭github.com/facebook/php-graph-sdk/issues/473 – luschn