检索fbsdk访问令牌和用户ID的问题 [英] Issues retrieving fbsdk Access Token and User ID
问题描述
我正在尝试在我的React Native App中检索登录用户的访问令牌和用户ID。出于某种原因,当我尝试更新fbsdkcore软件包时,它不再存在了。所以,我试图在一般的fbsdk包中解决它。
I am trying to retrieve the Access Token and User ID of the logged in user in my React Native App. For some reason when I tried to update the fbsdkcore package, it did not exist anymore. So, I tried to resolve it within the general fbsdk package.
我正在调用包中的js文件(我认为它检索了accesstoken):
I am calling the js file (of which I think retrieves the accesstoken) in the package as:
const AccessToken = require('react-native-fbsdk/js/FBAccessToken');
随后在我的代码中我尝试记录它以便我可以看到它是否有效,只需通过:
And subsequently in my code I try to log it so that I can see if it works, simply by:
console.log(AccessToken.getCurrentAccessToken());
console.log(AccessToken.getUserId);
但是日志只返回:
2016-05-05 10:22:28.276 [info][tid:com.facebook.React.JavaScript] { _45: 0, _81: 0, _65: null, _54: null }
2016-05-05 10:22:28.277 [info][tid:com.facebook.React.JavaScript] undefined
这似乎不是我正在寻找的机器人。
Which does not seem to be the droids that im looking for.
我检查了fbsdk包中的js文件的代码和 getCurrentAccessToken
代码如下所示:
I inspected the code for the js file in the fbsdk package and the getCurrentAccessToken
code looks like this:
/**
* Getter for the access token that is current for the application.
*/
static getCurrentAccessToken(): Promise<?FBAccessToken> {
return new Promise((resolve, reject) => {
AccessToken.getCurrentAccessToken((tokenMap) => {
if (tokenMap) {
resolve(new FBAccessToken(tokenMap));
} else {
resolve(null);
}
});
});
}
这当然看似合理。但是,当我试图调用它时,我得到了这个非常奇怪的结果,我担心我在大局中做错了什么。我甚至修改了 resolve(null)
部分代码,以便我可以确定发生了什么。但它仍然返回相同的奇怪令牌。
Which of course seems reasonable. But since I get this really weird result when I try to call it, I get worried over that I have done something wrong in the bigger picture. I even modified the resolve(null)
part of the code so that I could make sure of what happend. But it still returned the same weird "token".
登录时日志也会返回此错误:
The log also returns this error when logging in:
2016-05-05 10:22:07.630 AppName[15097:415865] -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"
但我认为这只是因为我的xcode模拟器上没有facebook应用程序。
But I think that is only because I don't have the facebook app on my xcode simulator.
有人能给我一个很好的猜测我做错了吗?
Can anybody throw me a good guess on what I have done wrong??
推荐答案
GetCurrentAccestoken
返回一个承诺。
也许你可以试试:
AccessToken.getCurrentAccessToken().then(
(data) => {
console.log(data.accessToken.toString())
}
)
这篇关于检索fbsdk访问令牌和用户ID的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!