繁体   English   中英

Github个人访问令牌在NodeJS中的api请求调用中不起作用

[英]Github personal access token not working in api request call in nodeJS

尝试在调用github API时使用个人访问令牌来克服速率限制。 我能够获得结果,直到达到速率限制为止。 之后,即使使用PAT,我也收到403禁止错误。 我正在使用令牌,如下所示。 一段时间后,我可以检索到速率限制重置等结果。

let request  = require('got')

const header = {
    json: true,
    headers: {'user-agent': 'aws'},
    Accept: "application/vnd.github.v3+json",
    Authorization: "token 989842948hbf24424244"
}

 let closedPRUrlResult = await request(closedPRUrl, header);
    console.log(closedPRUrlResult.body.total_count);

在进行get调用时在标头中使用PAT的正确方法是什么?

error null
(node:47848) UnhandledPromiseRejectionWarning: HTTPError: Response code 403 (Forbidden)
    at EventEmitter.emitter.on (/Users/username/Desktop/Automate/node_modules/got/source/as-promise.js:74:19)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:47848) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

对于您的情况,请检查查询是否缺少有效的User-Agent标头

我们要求您使用GitHub用户名或应用程序名称作为User-Agent标头值。
如果有问题,我们可以与您联系。

如果您通过cURL(或通过备用客户端)提供了无效的User-Agent标头,则会收到403 Forbidden响应。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM