我正在使用 https://github.com/Wizcorp/phonegap-facebook-plugin 将我的CordovaAndroid应用程序连接到Facebook。
我可以通过以下方式登录:
facebookConnectPlugin.login(["email"],
fbLoginSuccess,
function (error) { alert("ERROR:" + JSON.stringify(error)); }
);
,注销甚至调用facebookConnectPlugin.getLoginStatus
并获得:
- 用户标识
- 访问令牌
- 过期在
- 西格
- 地位
但是当
FB.api('/me', function(response){...})
被召唤时,我会收到
{error:
{
message: An active access token must be used to query information about the current user,
type: OAuthException,
code: 2500
}
}
此外,这仅在构建应用程序时发生,而不是在浏览器中进行测试。
通过手动为FB.api
调用令牌解决了问题:
FB.api('/me?access_token='+userdata.authResponse.accessToken, function(response) {...
其中userdata
是facebookConnectPlugin.getLoginStatus
的回应我只是不明白为什么它不像在浏览器中那样在 android 应用程序中自动提供令牌。
使用 apiString 发送访问令牌和数据检索字段
const fields = ['email', 'first_name', 'last_name', 'gender', 'birthday', 'picture.type(large)'];
const apiString = `me?access_token=${accessToken}&fields=${fields.join(',')}`;