我尝试了各种实现来连接到 Mailchimp OAuth API。以下是我当前产生错误的代码:
"Invalid grant_type parameter or parameter missing"
我尝试过 x-www-form-urlencoded 内容类型,对正文进行字符串化并更改标题。
let body = {
"grant_type": "authorization_code",
"client_id": Meteor.settings.public.mailchimp.clientId,
"client_secret": Meteor.settings.private.mailchimp.secret,
"redirect_uri": Meteor.settings.public.mailchimp.redirect_uri,
"code": code,
}
HTTP.call("POST",
`https://login.mailchimp.com/oauth2/token`, {
data: body,
headers: {
"Content-Type": "application/json",
"Content-Encoding": "",
"User-Agent": "oauth2-draft-v10"
},
npmRequestOptions: {
"gzip": true //Required to read error
}
}
... Code continued
他们的文档没有说明我遗漏的任何明显内容 http://developer.mailchimp.com/documentation/mailchimp/guides/how-to-use-oauth2/
肯定有一个标题或我丢失的东西。
最佳答案
来自邮件 chimp 文档示例(此处 https://developer.mailchimp.com/documentation/mailchimp/guides/how-to-use-oauth2/ ):
curl --request POST \
--url 'https://login.mailchimp.com/oauth2/token' \
--data "grant_type=authorization_code&client_id={client_id}&client_secret={client_secret}&redirect_uri={encoded_url}&code={code}" \
--include
它需要 URL 形式编码的帖子正文而不是 JSON。
关于javascript - "Invalid grant_type parameter or parameter missing"Mailchimp OAUTH token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48988772/