Facebook Access Token [Javascript SDK]

旧城冷巷雨未停 提交于 2019-12-20 06:18:34

问题


I am writing Facebook login for my site.I am using Javascript Sdk,but I don't understand one thing.

  function fbLogin() {
   FB.login(function(response) {
   if (response.authResponse) {
    var token=response.authResponse.accessToken;
     FB.api('/me', function(response) {

       $.get('main/check_facebook_status/'+token,function(data) {
            if (data == "true") {
                $('#r_name').val(response.name);
                $('#r_username').val(response.username);
                $('#r_email').val(response.email);
                $('#fbid').val(response.id);
                $('#fbtoken').val(token);


            }
       })
     });
   } else {
     console.log('User cancelled login or did not fully authorize.');
   }
 }, {scope: 'email, publish_stream'});
  }

Can I trust he access token(response.authResponse.accessToken) for identify the user ? Can facebook change the access token ? If changes the access token how can I identify the user ?

Ps:Sorry for bad english


回答1:


Can I trust he access token(response.authResponse.accessToken) for identify the user?

Of-course yes!

Can Facebook change the access token ?

Nope. But it expires after 2 hours, so you have to get the token again. If you want to use this token in future; you can extend the life of the token to 60 days.

You can read more about access tokens here.


[Edit]

The token also becomes invalidated in the following cases-

  • User changes the password
  • User de-authorizes the app
  • User removes the app


来源:https://stackoverflow.com/questions/19884126/facebook-access-token-javascript-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!