Issues with the AccessToken in the React Native FBSDK

蹲街弑〆低调 提交于 2019-12-12 01:43:42

问题


I am having trouble with my ability to get the AccessToken in the fbsdk in React Native.

I am calling the core as suggested by Facebook:

const FBSDKCore = require('react-native-fbsdkcore');
const {
  FBSDKAccessToken,
} = FBSDKCore;

And in one scenario I try to write the token in the log as suggested by a similair question stated here on SO.

    <View>
        <View style={{flex: 1, alignItems: 'center', padding: 50, marginTop: 250}}>
        <View> 
          <LoginButton
            publishPermissions={["publish_actions"]}
            onLoginFinished={
              (error, result) => {
                if (error) {
                  alert("login has error: " + result.error);
                } else if (result.isCancelled) {
                  alert("login is cancelled.");
                } else {
                  FBSDKAccessToken.getCurrentAccessToken((token)=> {
                        console.log(token);
                      });                          
                  Actions.Navigator()
                }
              }
            }
            onLogoutFinished={() => {
              alert("logout.")}}/>
        </View>
        </View>
    </View>

This gives me the redscreen "undefined is not an object (evaluating the FBSDKAccessTokenInterface.getCurrentAccessToken)

Trying to pull off something similair in other parts of the app, of course defining the const FBSDKAccessToken first, then calling the userID (which should be a part of the FBSDKCore) as:

<Text style={{fontSize: 18, color:colors.General.navtext}}>{FBSDKAccessToken.userID}</Text>

Yields nothing, where I believed it to return the userID of the logged in user. Also, if I try to write out the accesstoken in that same place as:

<Text style={{fontSize: 18, color:colors.General.navtext}}>{FBSDKAccessToken.getCurrentAccessToken()}</Text>

I get the same red screen as before.

I tried to look in to the linking of libraries, but that even caused further problem.

Hence, from this, I am pretty stranded and I would really appreciate some feedback on what has gone wrong.


回答1:


Try this.

console.log(token.accessToken.toString());


来源:https://stackoverflow.com/questions/37029783/issues-with-the-accesstoken-in-the-react-native-fbsdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!