我来自 facebook 的“access_token”是“不正确的值”

5 facebook django-rest-framework django-allauth django-rest-auth react-native

我正在使用 django-rest-auth,它是“Django all-auth 的 API 扩展”。我正在构建一个可以使用 Facebook 令牌注册/登录的移动应用程序(网址:http://localhost:8000/rest-auth/facebook/)。

  1. 使用“博览会”获取 Facebook 令牌

    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);
    };
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在 Http POST 请求中包含令牌

    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 });
      });
    }
    
    Run Code Online (Sandbox Code Playgroud)
  3. 我收到 400 错误。所以我打印了在 localhost 浏览器和 Postman 上测试的令牌。并且都返回

    {
        "non_field_errors": [
            "Incorrect value"
        ]
    }
    
    Run Code Online (Sandbox Code Playgroud)

为什么我收到 400 Incorrect value 错误?

  • 设置.py

    SITE_ID = 7 # 我从 shell 中搜索了相应的 SITE_ID。

  • 行政

    Social_Application。=>

    provider: Facebook
    name: ~
    Client id:~
    Secret Key: ~
    Chosen Sites: 'http://localhost:8000'
    
    Run Code Online (Sandbox Code Playgroud)

我想我为“access_token”设置了错误的值。我们不能从 expo.Facebook.logInWithReadPermissionsAsync 放置令牌吗?。由于 FB 代币随时间变化。

cra*_*ler 1

在社交应用程序的管理页面 ( http://localhost:8000/admin/socialaccount/socialapp/1/change/ ) 中,您需要为 Facebook 提供商指定“密钥”。