使用 react-native facebook SDK 获取用户应用令牌
Getting user app token using react-native facebook SDK
我已经在登录请求中使用新的 https://github.com/facebook/react-native-fbsdk, however I can'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 returns 登录 facebook,但新的 FB sdk 没有,github 页面上的文档没有在任何地方提到它。
经过更多挖掘后找到了答案。您需要使用 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>
);
}
});
您不需要第三方模块(react-native-fbsdkcore
)
软件包 (react-native-fbsdk
) 在其 Github 页面上有说明:https://github.com/facebook/react-native-fbsdk#usage
用户登录后,您可以按如下方式获取访问凭据:
import { AccessToken } from 'react-native-fbsdk';
AccessToken.getCurrentAccessToken().then(data => {
console.log(data.accessToken.toString())
})
我已经在登录请求中使用新的 https://github.com/facebook/react-native-fbsdk, however I can'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 returns 登录 facebook,但新的 FB sdk 没有,github 页面上的文档没有在任何地方提到它。
经过更多挖掘后找到了答案。您需要使用 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>
);
}
});
您不需要第三方模块(react-native-fbsdkcore
)
软件包 (react-native-fbsdk
) 在其 Github 页面上有说明:https://github.com/facebook/react-native-fbsdk#usage
用户登录后,您可以按如下方式获取访问凭据:
import { AccessToken } from 'react-native-fbsdk';
AccessToken.getCurrentAccessToken().then(data => {
console.log(data.accessToken.toString())
})