我正在使用phonegap facebook插件和facebook javascript api.这是我的代码
FB.init({
appId: "xxxxxxxxxxxxxxx",
status: true,
oauth :true,
nativeInterface: CDV.FB,
//channelURL : 'www', // Channel File
cookie: true,
//useCachedDialogs: false,
xfbml: true
});
FB.login(function(response) {
if (response.authResponse) {
alert(response.authResponse.userID); // literally shows three dots
FB.api('/me', function(me){
if (me.id) {
alert(me.id); // this works
}
});
}
}, { scope: "email" });
我可以从authResponse获取accessToken ….它是一个长字符串.但是userID字段实际上是“……”.我可以通过对服务器进行额外的往返来获取用户的ID,并使用另一个图形API调用fetch / me,但这似乎很浪费.
解决方法:
[为了OP的利益]您可以在开始显示时通过额外调用服务器来获取客户端中的userID.这是正确的代码:
FB.api('/me', function(me){
if (me.id) {
var facebook_userid = me.id;
alert(facebook_userid);
}
});
这并不能解释为什么userID字段在登录响应对象中是“…”.但这是一种解决方法.
原文地址:https://codeday.me/bug/20190613/1233195.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。