问题
I'm using django-rest-auth which is "API extension for Django all-auth". I'm building a mobile app which can signup/login using Facebook token (url: http://localhost:8000/rest-auth/facebook/).
get Facebook token using 'expo'
export const doFacebookLogin = () => async dispatch => { let { type, token } = await Facebook.logInWithReadPermissionsAsync('194632xxxxxx', { permissions: ['public_profile'] }); if (type === 'cancel') { return dispatch({ type: FACEBOOK_LOGIN_CANCEL }) } doSocialAuthLogin(dispatch, token); };
Include token in Http POST request
const doSocialAuthLogin = async (dispatch, token) => { console.log(token); axios.post(`${ROOT_URL}/rest-auth/facebook/`, { access_token: token }).then(response => { AsyncStorage.setItem('stylee_token', response.data.token); dispatch({ type: AUTH_LOGIN_SUCCESS, payload: response.data.token }); }) .catch(response => { if(response.status === 400) { console.log('Not authorized. '); } else if (response.status === 403){ console.log('You are not suposed to see this message. Contact Administrator'); } dispatch({ type: SOCIAL_FACEBOOK_LOGIN_FAIL }); }); }
I got 400 error. So I printed the token tested on localhost browser and Postman. And both returns
{ "non_field_errors": [ "Incorrect value" ] }
Why am I getting 400 Incorrect value error?
settings.py
SITE_ID = 7 # I searched for corresponding SITE_ID from shell.
admin
Social_Application. =>
provider: Facebook name: ~ Client id:~ Secret Key: ~ Chosen Sites: 'http://localhost:8000'
I think I put wrong value for 'access_token'. Can't we put token from expo.Facebook.logInWithReadPermissionsAsync?. Since FB token changes over time.
来源:https://stackoverflow.com/questions/46098317/my-access-token-from-facebook-is-incorrect-value