How do I renew a Facebook user_access_token if I deal with a lot of AJAX?

后端 未结 7 1086

Please tell me if I\'m understanding correctly. (because I might not be.)

  1. User posts something on my site. (He checked \"also post to Facebook\".)
  2. Client
7条回答
  •  一整个雨季
    2021-02-09 13:16

    Like @ThinkingStiff said, the key point is that you need to call FB.getLoginStatus() on the client to get the latest access token

    These days, all the cool kids are handling their logins and retrieving their access tokens via JavaScript with the SDK. And hey, why not? The users love it!

    After the JavaScript SDK retrieves the access token, all AJAX requests to your server will have access to that access token as well. That is, it is automatically passed along with each AJAX request in the form of a cookie.

    So, on the server side, you can retrieve the access token via cookies (our friend StackOverflow has some Answers related to finding that cookie). However, if you do the other cool thing and use the PHP SDK you won't even have to give it a second thought, because it will automatically grab the cookie for you, if it's there!

提交回复
热议问题