Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook access_token invalid?

Tags:

facebook

oauth

I'm attempting to use the new Graph API Facebook recently released, but I can't seem to get it to work correctly.

I've gone through the steps, and after the /authorize call, I receive an access_token:

access_token=109002049121898|nhKwSTJVPbUZ5JYyIH3opCBQMf8.

When I attempt to use that token I get:

{
   "error": {
      "type": "QueryParseException",
      "message": "An active access token must be used to query information about the current user."
   }
}

I'm stumped as too why...

-AC

like image 859
Alex Cook Avatar asked Apr 24 '10 18:04

Alex Cook


People also ask

How do I fix an invalid access token on Facebook?

Please click on Facebook Ads Extension, Manage Settings, go to Advanced options and click on Update token.

What is FB token error?

Message: Error validating access token: The user is enrolled in a blocking, logged-in checkpoint. This error message means that your Facebook user account has failed a security checkpoint and needs to log in at Facebook or the Facebook Business Manager to correct the issue.

How can I check if my Facebook access token is valid?

You can simply request https://graph.facebook.com/me?access_token=xxxxxxxxxxxxxxxxx if you get an error, the token is invalid. If you get a JSON object with an id property then it is valid. Unfortunately this will only tell you if your token is valid, not if it came from your app.

What does invalid access token mean?

This error means that the app has experienced an authentication problem and can't verify your account information. If it occurs, you'll be automatically signed out of your account.


2 Answers

Just to clarify -- after you call

https://graph.facebook.com/oauth/authorize?

you should receive a CODE which, in conjunction with your CLIENT_ID and CLIENT_SECRET (assuming you have registered your application) can be exchanged for an access_token at

https://graph.facebook.com/oauth/access_token?

If this is indeed how you came by your ACCESS_TOKEN, you should then be able to request

https://graph.facebook.com/me/
like image 126
Bosh Avatar answered Oct 18 '22 03:10

Bosh


When using your Facebook Application's token

If you're using the me alias as in https://graph.facebook.com/me/ but your token is acquired for a Facebook Application, then "me" isn't you anymore - it's the app or maybe nothing. Anyway, that's not your intention for the app to interact with itself.

In this case you will want to interact with your personal user account from an app. What you need to do (after giving the app the permissions it requests in the UI when it asks) is find your facebook userid # and put it in place of "me" to access your own info. e.g. Mark Zuckerberg's facebook userid is 4 so he is https://graph.facebook.com/4/

The alias me only works if you're you! Sometimes it's hard to remember who the current user is when programming facebook (i.e. you, the Page, the App, etc) because we're accustomed to using the facebook UI as ourselves most of the time. From a programming standpoint it depends on what the acquired token represents.

A great blog post that always helps correct me is Ben Biddington | Facebook Graph API — getting access tokens.

like image 33
John K Avatar answered Oct 18 '22 02:10

John K