简体   繁体   中英

Facebook API Access token

Hello I am reading the Facebook API docs but I need a simple Help.

$token_url = "https://graph.facebook.com/oauth/access_token?"
       . "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
       . "&client_secret=" . $app_secret . "&code=" . $code;

I do understand all the variables...

But I do NOT understand what is $code

What is that variable?

I just need to get the last status of the user from the Facebook Feed.

I need to generate the Access Token, but I do not really know what that $code means??

Please help.

This is explained thoroughly in Facebook Developers Documentation here .

If the user presses Allow, your app is authorized. The OAuth Dialog will redirect (via HTTP 302) the user's browser to the URL you passed in the redirect_uri parameter with an authorization code:

http://YOUR_URL?code=A_CODE_GENERATED_BY_SERVER

After you recieve this code you can use it to get an access token:

In order to authenticate your app, you must pass the authorization code and your app secret to the Graph API token endpoint at https://graph.facebook.com/oauth/access_token .The app secret is available from the Developer App and should not be shared with anyone or embedded in any code that you will distribute (you should use the client-side flow for these scenarios).

 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

there is a better way.

goto https://developers.facebook.com/tools/explorer/ and generate a new access token after selecting the scope and then when you hit any API in place of code, use access_token=<%new generated token %>, you can extend that token validity to 3 months as well. so you dont need to hit

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

again and again. maybe you need to call loginFB() that automatically gets the token. hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM