gpt4 book ai didi

node.js - 23andMe API 错误 : 'No grant_type provided.' 'invalid_request' OAuth2

转载 作者:搜寻专家 更新时间:2023-11-01 00:06:08 25 4
gpt4 key购买 nike

我正在使用 OAuth 2 使用 23andMe API 进行身份验证。在用户授予访问权限后,我能够收到代码。我目前正在尝试发送发布请求以接收访问 token 。我继续收到此错误:

 data: 
{ error_description: 'No grant_type provided.',
error: 'invalid_request' } }

我正在使用 axios 包来发出我的帖子请求。我的请求中有错误,因为我在 curRL 时获得了成功的 200 响应和访问 token :

 curl https://api.23andme.com/token/
-d client_id='zzz' \
-d client_secret='zzz' \
-d grant_type='authorization_code' \
-d code=zzz \
-d "redirect_uri=http://localhost:3000/receive_code/"
-d "scope=basic%20rszzz"

我能够从 23andMe 服务器接收到授权码。然后我被重定向到我的应用程序。这是我的 GET 路线:

router.get('/receive_code', function(req, res) {

axios.post('https://api.23andme.com/token/', {

client_id: zzz,
client_secret: zzz,
grant_type: 'authorization_code',
code: req.query.code,
redirect_uri: 'http://localhost:3000/receive_code/',
scope: "basic%20rs3094315"

}).then(function (response) {
console.log(response);

}).catch(function (error) {
console.log(error);
});
});

有什么想法吗?

最佳答案

问题是您放置在负载中的 form 键。它应该像这样工作:

axios.post('https://api.23andme.com/token/', {  client_id: zzz,  client_secret: zzz,   grant_type: 'authorization_code',  code: req.query.code  redirect_uri: 'http://localhost:3000/receive_code/',  scope: "basic%20rs3094315"}).then(function (response) {  console.log(response);}).catch(function (error) {  console.log(error);});

关于node.js - 23andMe API 错误 : 'No grant_type provided.' 'invalid_request' OAuth2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38781020/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com