我需要处理react-native中的Facebook登录错误。React Native FB SDK处理验证拒绝
尝试登录后重新安装我的应用程序的显示弹出式用户:
"Facebook. Application would like to access your basic profile info and list of friends."
两个选项:“不允许”和“OK”。正常的流量,我得到一个适当的令牌。但是,如果用户在onLoginFinished
拒绝我得到以下结果:
{
"isCancelled": true,
"grantedPermissions": null,
"declinedPermissions": null
}
其中有没有关于它为什么被取消的信息。拒绝是唯一的理由"isCancelled": true
与'system_account'
?
之后,所有的连续尝试与'system_account'
登录立即失败,并出现以下错误:
{
"code": "FacebookSDK",
"domain": "com.facebook.sdk.login",
"framesToPop": 1,
"nativeStackIOS": [...],
"userInfo": {
"NSLocalizedDescription": "Access has not been granted to the Facebook account. Verify device settings.",
"com.facebook.sdk:FBSDKErrorLocalizedDescriptionKey": "Access has not been granted to the Facebook account. Verify device settings."
}
}
它给我,我可以展示给用户的错误,但被本地化我不能可靠地解析它。所以问题是如何可靠地检测用户何时不授予权限?
的代码,我有:
import React from 'react'
import {AccessToken, LoginManager} from 'react-native-fbsdk'
class Login extends React.Component {
login =()=>{
LoginManager.setLoginBehavior('system_account')
LoginManager.logInWithReadPermissions()
.then(this.onLoginFinished)
.catch(this.onLoginError)
}
onLoginFinished = (result)=>{
if(result.isCancelled) {
//
} else {
AccessToken.getCurrentAccessToken().then((data)=>{
this.props.onLogin(data.accessToken.toString())
})
}
}
onLoginError = (error)=>{
// Want to handle this case but
//can only show a message to the user =(
}
render() {
return (
<View>
<TouchableHighlight onPress={this.login}>
<View><Text>Facebook</Text></View>
</TouchableHighlight>
</View>
)
}
}
从我能想到的我只能接受与'system_account'
取消和单独处理其行为的唯一途径后使切换到'native'
登录行为?