Facebook OAuth access_token return HTTP 400 Error Validating Verification Code

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

I was following the guides at Facebook Developers to do OAuth on the server side. In summary:

  1. Redirect the user to https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL
  2. After user click allow, it'll hit our Redirect Uri
  3. At that point we'll get the code and we need to do a server side HTTP Get to the following Url to exchange the code with our oAuth 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

Now at step 3, I kept on getting Http 400 response back.

So after some research, I found out that on that redirect_uri that we submitted on step 3 doesn't do anything but validate the request. Thus, the value need to match with step 2.

Finally! Phew.

  1. Aleksandr says:

    I've seen this fucking expample for about 1000 times. Please send me something else. How to authenticate, get access_tocken and send message to wall?

  2. Mcbodo says:

    This post was a really life saver. I spent the last 2 days trying to understando why it wasn't working! :D

  3. ronaldwidha says:

    glad that I could help

  4. Amitzu89 says:

    Thanks Dude!!! It saved ma day ;)

  5. Michal says:

     Thanks man :)

  6. cooldriver says:

    Thanks a lot man :-)

  7. Hugodemiglio says:

    Thanks a lot!! =D

  8. Poulsq says:

    Ok, i have to tell thank you, because  this f*cking facebook api make me crazy for such a little problem ... Thanks man !

  9. deype0 says:

    Thanks!

  10. bob says:

    You have saved countless lives.

  11. Roland Krinner says:

    Thanks a lot, you saved my day!