嗨爵士使用Fb Php Sdk 4&图2.8我知道它有点过时但我想继续它。只有已修复的授权问题才能完成我的项目
我使用过配置&登录数据页面下面,但它返回我
图表返回错误:已使用此授权码。
在我的代码下面
的config.php
<?php
session_start();
$_IM=array(
"sitename" => "AppsFunny",
"siteurl" => "http://appsfunny.com",
"sitelogo" => "AppsFunny.Com",
"fb_page" => "/appsfunny",
"aurl" => "appsfunny.com"
);
include "ifunc.php";
include "db.php";
include "Unicode2Bijoy.class.php";
$app_id='423436984657946';
require_once __DIR__ . '/vendor/autoload.php';
use Facebook\FacebookRequest;
$fb = new Facebook\Facebook([
'app_id' => $app_id,
'app_secret' => 'c82ff16cec2f6a055302c5c632c0129b',
'default_graph_version' => 'v2.8',
]);
if (isset($_SESSION['access_token'])) {
$token = $session->getToken();
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get('/me', $token);
} 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();
$_SESSION['FBID'] = $user['id'];
$_SESSION['FULLNAME'] = $user['name'];
$_SESSION['propic']="https://graph.facebook.com/".$_SESSION['FBID']."/picture?height=200&width=200";
}
?>
和login.php
<?php
require_once __DIR__ . '/config.php';
$p=$_GET["p"];
$helper = $fb->getRedirectLoginHelper();
$_SESSION['FBRLH_state']=$_GET['state'];
try {
$accessToken = $helper->getAccessToken();
}
catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage(); exit;
}
catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (isset($accessToken)) {
$access_token = $session->getToken();
$_SESSION['access_token'] = (string) $accessToken;
header("location:".$p);
}
答案 0 :(得分:0)
存在此问题是因为您试图在每次加载或重新加载页面时请求access_token
。当您请求令牌时,将随URL传递唯一的代码。当您一次又一次使用相同令牌请求时,就会发生此错误。
因此,在获取access_token
之后,请将其保存在db
中。并且仅当您没有access_token
或它不再有效时,才请求新令牌。