My 'access_token' from facebook is “incorrect value”

北城余情 提交于 2019-12-07 12:57:59

问题


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/).

  1. 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);
    };
    
  2. 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 });
      });
    }
    
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!