我需要處理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'
登錄行爲?