Google Apps脚本中的StackExchange API身份验证(StackExchange API authentication in Google Apps Script)

编程入门 行业动态 更新时间:2024-10-26 20:26:55
Google Apps脚本中的StackExchange API身份验证(StackExchange API authentication in Google Apps Script)

我正在尝试在Google Apps脚本中使用StackExchange API的V2.2。

当我尝试发送POST请求以获取访问令牌时,问题出现在显式OAuth 2.0流的最后一步。 我收到404错误,但手动发出相同的请求(使用邮递员扩展)一切正常。

为了简化问题,如果我发送没有有效负载的POST请求,我会收到相同的404

var response = UrlFetchApp.fetch("https://stackexchange.com/oauth/access_token", { method: 'post', muteHttpExceptions: true }); Logger.log(response);

在邮递员中,我收到400:

{ "error": { "type": "invalid_request", "message": "client_id not provided" } }

我想这会是UrlFetchApp的一个问题,但有谁知道如何解决它? 谢谢!

I'm trying to use the V2.2 of StackExchange API in Google Apps Script.

The problem comes in the last step of the explicit OAuth 2.0 flow, when I try to send the POST request to obtain the access token. I receive a 404 error, but making the same request manually (using postman extension) everything is ok.

To simplify the problem, if I send this POST request with no payload I receive the same 404

var response = UrlFetchApp.fetch("https://stackexchange.com/oauth/access_token", { method: 'post', muteHttpExceptions: true }); Logger.log(response);

while in postman I receive this 400:

{ "error": { "type": "invalid_request", "message": "client_id not provided" } }

I guess this will be a problem with UrlFetchApp, but does anyone know how to solve it? Thanks!

最满意答案

该问题与Origin标头有关。

你不能直接从标题中删除,但你可以通过代理执行调用:)

The problem is related with the Origin header.

You cannot remove from the header directly but you can perform the call via a proxy :)

更多推荐

本文发布于:2023-07-21 09:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1208971.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   身份验证   Google   Apps   StackExchange

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!