0

所以我试图使用reduxreact-native-fbsdk包一起登录一个用户,但是不管我如何去做,权限总是被拒绝,即使在登录后授予它们屏幕。控制台日志可以看到下面:React Native:Facebook的权限总是被拒绝

Console logs

这里你可以看到我的authFailure行动:

export function authFailure(authError) { 
    return { 
    type: AUTH_FAILURE, 
    action.authError.message 
    } 
} 

这里是获取onPress派遣行动authStarted(),然后调用函数执行的功能处理fbsdk的_fbAuthAPI()。这可以在下面看到。

export function _fbAuth() { 
    return (dispatch) => { 
    dispatch(authStarted()) 
    const values = [] 
    _fbAuthAPI().then((result) => { 
     values.concat(result.accessToken) 
     return _getUserInformationAPI(result.accessToken) 
    }).then((profile) => { 
     values.concat(profile) 
     dispatch(authSuccess(...values)) 
    }).catch((error) => { 
     dispatch(authFailure(error)) 
     setTimeout(() => { 
     dispatch(authFailureRemove()) 
     }, 4000) 
    }) 
    } 
} 

export function _fbAuthAPI() { 
    return new Promise((resolve, reject) => { 
    LoginManager.logInWithReadPermissions(['public_profile', 'email']).then((result) => { 
     if (result.isCancelled) { 
     throw new Error('Login was cancelled') 
     } else if (result.declinedPermissions) { 
     throw new Error('Permissions were declined') 
     } else { 
     return AccessToken.getCurrentAccessToken() 
     } 
    }).then((result) => { 
     resolve(result) 
    }).catch((error) => { 
     reject(error) 
    }) 
    }) 
} 

至于减速:

export default function authReducer(state = initialState, action) { 
    switch (action.type) { 
    case AUTH_STARTED: 
     return Object.assign({}, state, { 
     authenticating: true 
     }) 
     break 
    case AUTH_SUCCESS: 
     return Object.assign({}, state, { 
     authenticating: false, 
     authError: false, 
     facebookToken: facebookToken, 
     facebookProfile: facebookProfile 
     }) 
     break 
    case AUTH_FAILURE: 
     return Object.assign({}, state, { 
     authenticating: false, 
     authError: authError 
     }) 
     break 
     ... 
    default: 
     return state 
    } 
} 

设置:

  • 阵营本地0.45.1
  • 阵营本土FBSDK “^ 0.6.1”
  • 终极版“^ 3.7.1”
  • MacOS的塞拉利昂10.12.6

回答

0

奥基,所以我设法解决这个问题。 基本上,当你调用declinedPermissionslogInWithReadPermissions的结果时,它总是返回true,因为它是一个数组。然后,即使你没有任何拒绝的权限,它也会视为真实。

简单的方法来解决它,只是为了看到最新的阵列中,并确定基于该怎么做:

// Returns an empty array, therefore evaluates to true 
    if (result.declinedPermissions) { 
    throw new Error('Permissions were declined') 
    } 

// The first index of the array is empty 
    if (result.declinedPermissions[0] === "") { 
    throw new Error('Permissions were declined') 
    } 
1

我无法与Facebook的SDK和认证,但authError帮助被未定义是因为在本节中,authError是真正的未定义

case AUTH_FAILURE: 
     return Object.assign({}, state, { 
     authenticating: false, 
     authError: authError // Where is this coming from? 
     }) 
     break 

我想你打算有authError: action.authError

+0

我计算过,一出,以及 - 但感谢它! 然而,这是我真正迷失在Facebook SDK的一部分。 –