Reputation: 26565
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" />
Upvotes: 1
Views: 11446
Reputation: 2004
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.
Upvotes: 4
Reputation: 14438
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.
Upvotes: 3