且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法从Facebook获取访问令牌。 OAuthException表示“验证验证码错误”

更新时间:2022-10-16 23:08:10

我最近处理了这个问题:一切都匹配,但是与OAuthException失败。使它工作的事情是改变重定向uri(在两个请求的流程)从:



http://foo.example.com





http://foo.example.com/



即可添加尾部斜线。然后它工作。愚蠢和愚蠢,但你去。


I am using java and the purpose of my demo application is simple: Update user status. I followed the Server-side Flow on page http://developers.facebook.com/docs/authentication. I got the auth dialog, facebook lead to the callback url and I got the code in my callback page. Then I failed when I try to generate an access token.

In the guide page, it says the following url could be used to generated an access token:

https://graph.facebook.com/oauth/access_token?
     client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&
     client_secret=YOUR_APP_SECRET&code=THE_CODE_FROM_ABOVE

But what happens in my environment is I got the following error message:

{
   "error": {
      "type": "OAuthException",
      "message": "Error validating verification code."
   }
}

I am quite sure every parameter is correct because if I change the client_id value or client_secret parameter, I will got a different error message. The code parameter is what I got from facebook callback. So this should be correct, right? Really can't figure out what is the problem....

Any idea about this? I get stuck here...

I recently dealt with exactly this problem: everything matched, but it failed with the OAuthException. The thing that made it work was to change the redirect uri (in both requests for the flow) from:

http://foo.example.com

to

http://foo.example.com/

I.e., add the trailing slash. And then it worked. Stupid and silly, but there you go.