我来自Facebook的“ access_token”是“不正确的值”, [英] My 'access_token' from facebook is "incorrect value"
问题描述
我正在使用django-rest-auth,它是 Django all-auth的API扩展。我正在构建一个可以使用Facebook令牌注册/登录的移动应用(网址: http:// localhost :8000 / rest-auth / facebook / )。
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/).
-
使用'expo'获取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);
};
在Http POST请求中包括令牌
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 });
});
}
我遇到400错误。因此,我在本地浏览器和Postman上打印了经过测试的令牌。两者都返回
I got 400 error. So I printed the token tested on localhost browser and Postman. And both returns
{
"non_field_errors": [
"Incorrect value"
]
}
我为什么得到400错误的值错误?
Why am I getting 400 Incorrect value error?
-
settings.py
settings.py
SITE_ID = 7#我搜索了外壳程序中对应的SITE_ID。
SITE_ID = 7 # I searched for corresponding SITE_ID from shell.
admin
Social_Application。 =>
Social_Application. =>
provider: Facebook
name: ~
Client id:~
Secret Key: ~
Chosen Sites: 'http://localhost:8000'
我认为我为'access_token'输入了错误的值。我们不能放置来自expo.Facebook.logInWithReadPermissionsAsync的令牌吗?由于FB令牌随时间变化。
推荐答案
在社交应用的管理页面中( http:// localhost:8000 / admin / socialaccount / socialapp / 1 / change / ),您需要为Facebook提供者指定秘密密钥。
In the admin page for the social app (http://localhost:8000/admin/socialaccount/socialapp/1/change/), you need to specify the "secret key" for Facebook provider.
这篇关于我来自Facebook的“ access_token”是“不正确的值”,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!