使用 javascript (response.authResponse.accessToken)后,如何使用访问令牌?
我希望每个人都可以向朋友发送消息(即使从Facebook登出后)。
编辑:
我刚试过这段代码,但它不起作用:
FB.api('/me?access_token=AAACZBLSe4fcoBAFcGMJZAUS9OthIr5o6ZCUySgXYj0nfWX7u08X7h0VZAFFuJJs9LmeWgud2u5ZCEZCeUHZCVIq1Y2j4gjKAjJ0gx5OY9PBihlABJn64njm', function(response) { });
function sendRequestto() {
FB.ui({
method: 'send',
name: 'hello',
to: '100000497530558',
description: 'yuhuuuuuuu'
});
}
并在身体中:
<input type="button" onclick="sendRequestto(); return false;" value="sendRequestto" />
答案 0 :(得分:3)
您所要做的就是保存access_token数据库/ cookie /会话,并在调用FB.api方法时,将访问令牌添加到图形URL中,如下所示
FB.api('/me/friends?access_token=...', function(response) {
alert(response.name);
});
要使访问令牌脱机,您必须获取offline_access权限或扩展有效访问令牌。
答案 1 :(得分:3)
像这样:
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.
}
});
无需显式使用访问令牌。 API为您做到了这一点。