How to use the access token?

南笙酒味 提交于 2019-12-13 18:03:21

问题


How to use the access token after I get it with javascript ( response.authResponse.accessToken ) ?

I want that everyone can send a message to a friend ( even after logged out from facebook ).

EDIT:

I have just tryed this code but it doesn't work:

FB.api('/me?access_token=AAACZBLSe4fcoBAFcGMJZAUS9OthIr5o6ZCUySgXYj0nfWX7u08X7h0VZAFFuJJs9LmeWgud2u5ZCEZCeUHZCVIq1Y2j4gjKAjJ0gx5OY9PBihlABJn64njm', function(response) { });

function sendRequestto() {
      FB.ui({
          method: 'send',
          name: 'hello',
          to: '100000497530558',
          description: 'yuhuuuuuuu'
          });    
}  

and in the body:

<input type="button" onclick="sendRequestto(); return false;" value="sendRequestto" /> 

回答1:


Like this:

FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
     FB.api('/me', function(response) {
       alert('Your name is ' + response.name);
     });
  } else if (response.status === 'not_authorized') {
    // the user is logged in to Facebook, 
    // but has not authenticated your app
  } else {
    // the user isn't logged in to Facebook.
  }
 });

There is no need to use the access token explicitly. The API does that for you.




回答2:


All you have to do is to save the access_token the database/cookie/session and while calling the FB.api method, append access token to the graph url like this

FB.api('/me/friends?access_token=...', function(response) {
  alert(response.name);
});

For using the access token offline, you must get the offline_access permission or extended validity access token.



来源:https://stackoverflow.com/questions/10435863/how-to-use-the-access-token

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