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的一部分。 –