criso / fbgraph

NodeJs module to access the facebook graph api
http://criso.github.io/fbgraph/
1.09k stars 176 forks source link

Getting access token & lifetime/expiration #97

Closed sam2x closed 7 years ago

sam2x commented 8 years ago

Hi,

I have a nodejs server that must interact with facebook graph api. I have created a developper account on facebook, and now i need to interact with the facebook graph api, i'm not sure what is the correct to get the access_token.

So : 1- I have my app developper account 2- I have my app id/secret, I want to generate an accesstoken to request graph api.
3- I request the graph api with the current accesstoken stored in my nodejs "conf" 3'- If the current accesstoken is expire, I want renew automatically the accesstoken on expiration.

On the docs it is written :

Authentication
If you get an accesstoken via some other Oauth module like everyauth , connect-auth or node-oauth you can just set the access token directly. Most get calls, and pretty much all post calls will require an access_token

"If you get an accesstoken via some other Oauth module" means for me that the accesstoken can be obtained also via this module ? What about the expiration time, or how can i automatically renew the token if he is invalid, must i use another module ?

Thanks you for your answer. Regards.

sam2x commented 8 years ago

Ok i have found that access_token for app are just app_id|app_secret. But now i have another problem, when i request the facebook graph api i got :

{
"error": {
  "message": "(#12) fql is deprecated for versions v2.1 and higher",
  "type": "OAuthException",
  "code": 12,
  "fbtrace_id": "XXXX"
}
}
sam2x commented 8 years ago

I have set

fbgraph.setVersion("2.0");

Not working. Still getting the same error :/

sam2x commented 8 years ago

Ok my app was created with the lastest current version of facebook (so 2.4). And facebook wont let me downgrade it to use fql. Like really, i cannot anymore use fql :/ ? Damn why they created it to suppress it one year later....

sam2x commented 8 years ago

Looks like no.

 "A reminder that API v2.0 will be deprecated in just over one year's time on Aug 7, 2016. If you are still using FQL, we recommend upgrading to API v2.1 or greater as soon as possible."
sam2x commented 8 years ago

Now using the normal graph api search, i get :

   { message: '(#200) Must have a valid access_token to access this endpoint',
 type: 'OAuthException'}

I don't understand, i cannot emit a graph api search with my own app information(app id/secret) ? Anyone know what is wrong ?

sam2x commented 8 years ago

Ok i finally succeeded to do it manually.

First we have to request : "https://graph.facebook.com/{appId}/accounts?access_token={appId}|{appSecret}" In the response we'll get the access_token. We can then perform simple search on the graph api without the need to use oauth authentication or any "redirect" scheme. Pretty useful for server-side request.

sam2x commented 8 years ago

facebook changed something recently, it's not working anymore.....

sam2x commented 8 years ago

worst api developper team ever... they really sucks...

gohackfelipe commented 7 years ago

Hey dudee.. Did you resolve this ? I am having the same problem! :(