Check alle échte Black Friday-deals Ook zo moe van nepaanbiedingen? Wij laten alleen échte deals zien

Vernieuw Access Token [Facebook SDK PHP]

Pagina: 1
Acties:

  • klepje
  • Registratie: Januari 2012
  • Laatst online: 19:53
Beste Tweakers,

ik probeer gebruik te maken van de Facebook SDK, om mijn eigen informatie (naam, etc) en mijn laatste facebook posts in mijn website te integreren. Ik krijg de goede informatie en dergelijke, alleen ik loop steeds tegen het probleem aan dat mijn access token na 2 uur verloopt.

Is het mogelijk dat ik deze access token automatisch verleng of een nieuwe aanvraag met de juiste permissies?

Voor de duidelijkheid: gebruikers van mijn website hoeven niet in te loggen, de enige informatie die ze te zien krijgen is van mij. Ik ben de beheerder van de facebook app en wil de informatie uit mijn profiel weergeven op mijn website, zonder dat ik steeds (om de 2 uur) een nieuwe access token aan moet maken.

Alvast bedankt!

  • DonKui
  • Registratie: November 2007
  • Laatst online: 11-05-2022

  • klepje
  • Registratie: Januari 2012
  • Laatst online: 19:53
Heb ik inderdaad al gekeken. Heb al meerdere blogs van Facebook gekeken en ook op Stackoverflow kon ik het niet echt gevonden krijgen.

Echter is de link die je geeft ook uit 2011, toen de permissie offline_access er nog was. Dat is er nu helaas niet meer.

  • Tharulerz
  • Registratie: April 2009
  • Laatst online: 10-04 05:16

  • ProfoundValue
  • Registratie: Oktober 2009
  • Niet online
https://developers.facebo...book-login/access-tokens/
Expiration and Extending Tokens

Facebook's official SDKs manage the lifetime of tokens for you. When using iOS, Android or our JavaScript SDK, the SDK will handle making sure that tokens are refreshed before they expire. For example, access tokens on the web often have a lifetime of about two hours, but will automatically be refreshed when required.

But if you want to use access tokens for longer-lived apps, especially server side, you need to generate a long-lived token. You get a long-lived access token by making a call to this endpoint:
code:
1
2
3
4
5
GET /oauth/access_token?  
    grant_type=fb_exchange_token&           
    client_id={app-id}&
    client_secret={app-secret}&
    fb_exchange_token={short-lived-token}
Note that the app secret is included in this API call, so you should never actually make the request client-side; instead implement some server-side code that makes the request, then pass the response containing the long-lived token back to your client-side code. This will be a different string to the original token, so if you're storing these tokens, replace the old one.

Apps are unable to exchange an expired short-lived token for a long-lived token. The flow above only works with short-lived tokens that are still valid. Once they expire, your app must send the user through the login flow again.

Refreshing Long-Lived Tokens

Even the long-lived access token will eventually expire. At any point, you can generate a new long-lived token by sending the person back to the login flow used by your app - note that the person will not actually need to login again, they have already authorized your app, so they will immediately redirect back to your app from the login flow with a refreshed token - how this appears to the person will vary based on the type of login flow that you are using, for example if you are using the JavaScript SDK, this will take place in the background, if you are using a server-side flow, the browser will quickly redirect to the Login Dialog and then automatically and immediately back to your app again.

After doing the above you will obtain a new short-lived token and then you need to perform the same exchange for a long-lived token as above.

In some cases, this newer long-lived token might be identical to the previous one, but we can't guarantee it and your app shouldn't depend upon it.

Extending Page Access Tokens

Apps can retrieve a Page access token from Page admin users when they authenticate with the manage_pages permission. If the user access token used to retrieve this Page access token is short-lived, the Page access token will also be short-lived.

To get a longer-lived Page access token, exchange the User access token for a long-lived one, as above, and then request the Page token. The resulting Page access token will not have any expiry time.

  • Cartman!
  • Registratie: April 2000
  • Niet online
Gewoon die token verlengen dus en de verlengde token opslaan ipv. je short lived token. Na 60 dagen wordt je long lived token weer ongeldig en moet je deze vernieuwen door jezelf opnieuw te authorizen. Omdat je in principe nog steeds authorized bent hoef je niet opnieuw toestemming te geven en stuurt ie je meteen een nieuwe short lived token mee die je weer kunt omwisselen voor een long lived. Die offline_access was voor developers wel een stuk handiger maar ik snap wel dat ze daar vanaf wilden.
Pagina: 1