Facebook 如何使用访问令牌?
使用javascript(response.authResponse.accessToken)获取访问令牌后,如何使用它 我希望每个人都可以向朋友发送消息(,即使在从facebook注销后) 编辑: 我刚刚尝试过此代码,但它不起作用:Facebook 如何使用访问令牌?,facebook,facebook-javascript-sdk,Facebook,Facebook Javascript Sdk,使用javascript(response.authResponse.accessToken)获取访问令牌后,如何使用它 我希望每个人都可以向朋友发送消息(,即使在从facebook注销后) 编辑: 我刚刚尝试过此代码,但它不起作用: FB.api('/me?access_token=AAACZBLSe4fcoBAFcGMJZAUS9OthIr5o6ZCUySgXYj0nfWX7u08X7h0VZAFFuJJs9LmeWgud2u5ZCEZCeUHZCVIq1Y2j4gjKAjJ0gx5OY9P
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" />
您所要做的就是将访问令牌保存到数据库/cookie/session中,并在调用FB.api方法时,将访问令牌附加到图形url中,如下所示
FB.api('/me/friends?access_token=...', function(response) {
alert(response.name);
});
要脱机使用访问令牌,您必须获得脱机访问权限或扩展有效性访问令牌。您所要做的就是将访问令牌保存到数据库/cookie/session中,并在调用FB.api方法时,将访问令牌附加到图形url中,如下所示
FB.api('/me/friends?access_token=...', function(response) {
alert(response.name);
});
要脱机使用访问令牌,必须获得脱机访问权限或扩展有效性访问令牌。如下所示:
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可以为您做到这一点。如下所示:
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为您做到了这一点。uhm,但如果用户在facebook上离线,则此功能不起作用:(vivek.uhm很好地描述了离线使用情况,但如果用户在facebook上离线,则此功能不起作用:(vivek很好地描述了离线使用情况。对不起,我刚刚尝试了你的代码,但显示了登录facebook的窗口。你能在上面编辑的帖子中看到我的代码吗?谢谢:)对不起,我刚刚尝试了你的代码,但显示了登录facebook的窗口。你能在上面编辑的帖子中看到我的代码吗?谢谢:)我错过了前面的一个正斜杠。编辑了我的示例。只需添加/before,我就会遇到同样的问题:(.alert(response.name)返回“undefined”。也许我需要请求一些特殊权限吗?从这个URL,我得到“会话无效,因为用户已注销”:…看到这个:我之前错过了一个正斜杠。编辑了我的示例。只需添加/在我遇到相同问题之前:(.alert(response.name)返回“undefined”。可能我需要请求一些特殊权限吗?从这个URL,我得到“会话无效,因为用户已注销”:…看到这个: