JS SDK getLoginStatus不返回userID或signedRequest [英] JS SDK getLoginStatus doesn't return userID nor signedRequest

查看:337
本文介绍了JS SDK getLoginStatus不返回userID或signedRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PhoneGap / Cordova与Facebook的插件。一切似乎工作除了getLoginStatus不工作作为定义在这里此处。当被调用时,它返回一些数据,但不是全部:它不返回userID或signedRequest。
下面是代码:

  FB.getLoginStatus(function(response){
if(response.status =='connected'){
var fb_uid = response.authResponse.userID;
var fb_signedRequest = response.authResponse.signedRequest;
alert('logged in ');
} else {
alert('not logged in');
}
});

userID用省略号(...)填充,而signedRequest未定义。



我设法通过对/ me的图调用来获取userID:

  FB.api('/ me',function(me){
if(me.id){
var fb_uid = me.id;
}
} );

我无法在文档中找到任何方式来获取signed_request,用于向Facebook用户验证用户已经连接到的远程服务(我已经进行了登录呼叫,因此用户是OK)。
基本上问题是我调用getLoginStatus返回

  {
status:'connected',
authResponse:{
session_key:true,
accessToken:'a long string ...',
expiresIn:'a number',
sig:'... ',//正是这个字符串
userID:'...'//正是这个字符串
secret:'...'//正是这个字符串
expirationTime:'a long number'
}
}

作为背景,当使用插件进行身份验证时,JavaScript SDK API会调用iOS / Android SDK来处理授权,然后将响应身份验证数据传回到JS部分。原生(iOS / Android)SDK不会获得签名的请求,以便能够将此传递给JS。这是为什么它是空的。



如果你使用最新的插件,你至少应该看到用户ID。从6月的一个可能没有通过这回。否则,作为一个解决方法,当您的JS代码中的认证成功时,您可以执行对/ me端点的调用以获取用户标识。请参阅Hackbook示例,这样做。


I'm using PhoneGap/Cordova with the facebook plugin. Everything seems to work except for getLoginStatus who is not working as defined here and here. When called, it returns some data, but not all: it doesn't return userID nor signedRequest. Here is the code:

FB.getLoginStatus(function(response) {
  if (response.status == 'connected') {
    var fb_uid = response.authResponse.userID;
    var fb_signedRequest = response.authResponse.signedRequest;
    alert('logged in');
  } else {
    alert('not logged in');
  }
});

userID is filled with ellipsis (...), while signedRequest is undefined.

I managed to get userID with a graph call to /me:

FB.api('/me', function(me){
  if (me.id) {
    var fb_uid = me.id;
  }
});

I wasn't able to find any way in the documentation to get a signed_request, which I have to use to authenticate the facebook user to a remote service to whom the user already connected to with facebook (I already made a login call so user is OK). Basically the problem is that my call to getLoginStatus returns

{
    status: 'connected',
    authResponse: {
        session_key: true,
        accessToken: 'a long string...',
        expiresIn:'a number',
        sig: '...',   //exactly this string
        userID:'...'  //exactly this string
        secret:'...'  //exactly this string
        expirationTime:'a long number'
    }
}    

instead of what documented

解决方案

As a background, when authentication happens using the plugin then the JavaScript SDK API calls the iOS/Android SDK to handle the authorization and then pass response auth data back to the JS part. The native (iOS/Android) SDKs do not get signed requests back to be able to pass this on to the JS. This is why it's empty.

If you use the latest plugin you should at least now be seeing the user ID. The one from June likely did not pass this back. Otherwise as a work around, you could perform a call to the /me endpoint when authentication is successful in your JS code to get the user id. See the Hackbook example that does this.

这篇关于JS SDK getLoginStatus不返回userID或signedRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆