gpt4 book ai didi

javascript - LinkedIn oauth 错误缺少必需的参数 "client_id"

转载 作者:行者123 更新时间:2023-11-29 10:28:07 26 4
gpt4 key购买 nike

所以我刚刚从 LinkedIn oauth 1.0 升级到 2.0,我已经收到这个错误大约一天了。我在 php 上看到了一篇关于它的帖子,但我无法在 Node JS (Javascript) 中弄清楚这是我当前的代码:

axios
.post("https://www.linkedin.com/oauth/v2/accessToken", {
grant_type: "authorization_code",
code: req.query.code,
redirect_uri: keys.linkedinCallbackURL,
client_id: keys.linkedinConsumerKey,
client_secret: keys.linkedinConsumerSecret
})
.then(res2 => {
console.log(res2);
})
.catch(error => {
console.log(error);
});

如果您有任何想法,请告诉我:)

PHP 解决方案链接:LinkedIn OAuth a required parameter "clien_id" is missing

LinkedIn 指南链接:https://developer.linkedin.com/docs/oauth2(第3步出现错误)

最佳答案

LinkedIn 文档要求您将数据作为 application/x-www-form-urlencoded 发送,他们向我们展示了这个示例:

POST /oauth/v2/accessToken HTTP/1.1
Host: www.linkedin.com
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&code=987654321&redirect_uri=https%3A%2F%2Fwww.myapp.com%2Fauth%2Flinkedin&client_id=123456789&client_secret=shhdonottell

Axios documentation 表示默认情况下主体被序列化为 JSON:

By default, axios serializes JavaScript objects to JSON.

为了正确序列化正文,您应该使用 querystring 模块,如下所示:

const querystring = require('querystring');

axios
.post("https://www.linkedin.com/oauth/v2/accessToken", querystring.stringify({
grant_type: "authorization_code",
code: req.query.code,
redirect_uri: keys.linkedinCallbackURL,
client_id: keys.linkedinConsumerKey,
client_secret: keys.linkedinConsumerSecret
}));

关于javascript - LinkedIn oauth 错误缺少必需的参数 "client_id",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53328295/

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