首页 文章

使用react-native facebook SDK获取用户app令牌

提问于
浏览
4

我已经使用新的https://github.com/facebook/react-native-fbsdk登录了facebook登录,但是我可以't seem to get the user token which is usually returned in the response. Anyone found a way to get this information? The other SDK' s https://github.com/magus/react-native-facebook-login在登录请求中返回它但新的FB sdk并没有在任何地方提及它 .

1 回答

  • 9

    经过一番挖掘后找到了答案 . 您需要使用fbsdkcore来访问用户令牌 . 继承人你是如何使用它的 .

    var FBSDKCore = require('react-native-fbsdkcore');
    var {
      FBSDKAccessToken,
    } = FBSDKCore;
    
    var Login = React.createClass({
      render: function() {
        return (
          <View>
            <FBSDKLoginButton
              onLoginFinished={(error, result) => {
                if (error) {
                  alert('Error logging in.');
                } else {
                  if (result.isCanceled) {
                    alert('Login cancelled.');
                  } else {
                    FBSDKAccessToken.getCurrentAccessToken((token) => {
                      console.log(token.tokenString);
                    })
                  }
                }
              }}
              onLogoutFinished={() => console.log('Logged out.')}
              readPermissions={[]}
              publishPermissions={['publish_actions']}/>
          </View>
        );
      }
    });
    

相关问题