Facebook的:"本授权code已使用","类型":" OAuthException"," code":100 [英] Facebook: "This authorization code has been used.","type":"OAuthException","code":100

查看:1333
本文介绍了Facebook的:"本授权code已使用","类型":" OAuthException"," code":100的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚升级到PHP 5.4.19和Facebook的PHP-SDK-V4。

I just upgraded to PHP 5.4.19 and facebook-php-sdk-v4.

难道只是我或者已经取得FB整合故意为难?举例来说,我不使用这样作曲家加载新类所需的特定(发现换自己)排序(不能我的共享主机上安装的话) - 这就够头疼!在的http://metah.ch/blog/2014/05/facebook-sdk-4-0-0-for-php-a-working-sample-to-get-started/不完全正确的。

Is it just me or has FB made the integration deliberately difficult?! For instance, I don't use Composer (can't install it on my shared host) so loading the new classes required a specific (discover-for-yourself) ordering - that was enough headache! The suggested solution at http://metah.ch/blog/2014/05/facebook-sdk-4-0-0-for-php-a-working-sample-to-get-started/ wasn't completely correct.

无论如何,当我终于得到它运行,并在启用服务器的API调用应用程序的秘密证据
应用程序的高级设置选项卡,被Facebook推荐我进入一个catch 22

Anyway, when I finally got it to run and enabled "App Secret Proof for Server API calls" under the App advanced settings tab as recommended by Facebook I got into a catch 22.

这是它:

1)为了让一个FB API调用从我的服务器,例如 $ =请求新FacebookRequest($会议上,GET,/我'); 我现在必须提供一个appsecret_proof参数

1) To make an FB API call from my server, e.g. $request = new FacebookRequest($session, 'GET', '/me'); I must now provide an appsecret_proof argument.

2)要创建appsecret_proof我需要的access_token即 $ appsecret_proof = hash_hmac('SHA256',$的access_token,$ app_secret);

2) To create an appsecret_proof I need an access_token i.e. $appsecret_proof= hash_hmac('sha256', $access_token, $app_secret);.

3)在这一点上得到只有$ _GET ['code']一的access_token,我必须通过做code交换
GET https://graph.facebook.com/oauth/access_token?
    CLIENT_ID = {APP-ID}
   &安培; REDIRECT_URI = {重定向-URI}
   &安培; client_secret = {应用秘密}
   &安培; code = {code-参数}

3) To get an access_token with only $_GET['code'] at this point, I must do code exchange via GET https://graph.facebook.com/oauth/access_token? client_id={app-id} &redirect_uri={redirect-uri} &client_secret={app-secret} &code={code-parameter}.

4)要调用FB为code交换我的错误 {错误:{消息:本授权code已被使用,型 OAuthException,code:100}}

4) To call FB for code exchange I get the error {"error":{"message":"This authorization code has been used.","type":"OAuthException","code":100}}.

两个问题出现,因此:

1)如何我还能得到的access_token除了通过code交换,这样我就可以使用该令牌创建appsecret_proof并依次调用FacebookRequest?

1) How else can I get an access_token except via code exchange, so that I can use that token to create an appsecret_proof and in turn call FacebookRequest?

2)/我如何把那个appsecret_proof到FacebookRequest?它是也许这样 $请求=新FacebookRequest($会议上,GET,/我,阵列(appsecret_proof=> $ appsecret_proof)); ?我似乎无法找到有关如何使用PHP API使用appsecret_proof的特定指令(这是清楚如何通过HTTP与图形API做到这一点)。

2) Where/How do I put that appsecret_proof into FacebookRequest? Is it perhaps this way $request = new FacebookRequest($session, 'GET', '/me', array("appsecret_proof" => $appsecret_proof));? I cannot seem to find the specific instruction on how to use appsecret_proof with PHP API (it is clear how to do it via http with Graph API).

推荐答案

女士们,先生们,我解决了这一切 - 我只需要使用 $的access_token = $会话级>为gettoken(); 。这帮助了我否定的呼吁这是造成OAuthException code交换,因为Facebook已经因为被使用超过一次改变了交流code的政策。

Ladies and Gentlemen, I resolved it all - I just needed to use $access_token = $session->getToken();. This helped me negate the call for code exchange which was causing OAuthException because Facebook has since changed their policy on the exchange code from being used more than once.

现在服务器的API调用应用程序秘密证据正确的应用程序的高级设置选项卡下所推荐的Facebook的功能。

Now "App Secret Proof for Server API calls" is properly enabled under the App advanced settings tab as recommended by Facebook.

因此​​,在完成具体的解决方案:

So the specific solution in complete:

$app_id = 'APPID'; $app_secret = 'APPSECRET';
FacebookSession::setDefaultApplication($app_id, $app_secret);
$redirect_url = "https://mydomain.com/login";
$helper = new FacebookRedirectLoginHelper($redirect_url);

try {
    $session = $helper->getSessionFromRedirect();
} catch (FacebookRequestException $ex) {
} catch (Exception $ex) {
}

if (isset($session)) {
    $access_token = $session->getToken();
    $appsecret_proof = hash_hmac('sha256', $access_token, $app_secret);
    $request = new FacebookRequest($session, 'GET', '/me', array("appsecret_proof" =>  $appsecret_proof));
    $response = $request->execute();
    $graphObject = $response->getGraphObject();

   echo print_r($graphObject, 1);
} else {
    echo '<a href="' . $helper->getLoginUrl() . '">Login</a>';
}

这篇关于Facebook的:&QUOT;本授权code已使用&QUOT;,&QUOT;类型&QUOT;:&QUOT; OAuthException&QUOT;,&QUOT; code&QUOT;:100的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆