尝试在调用 github api 时使用个人访问 token 来克服速率限制。我能够得到结果,直到达到速率限制为止。之后,即使我使用 PAT,我也会收到 403 禁止错误。我正在使用 token ,如下所示。一段时间后,我能够检索结果,例如速率限制被重置。
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 调用时在 header 中使用 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)
最佳答案
就您的情况而言,请检查您的查询是否缺少 valid User-Agent
header
We request that you use your GitHub username, or the name of your application, for the
User-Agent
header value.
This allows us to contact you if there are problems.If you provide an invalid User-Agent header via cURL (or via an alternative client), you will receive a
403 Forbidden
response.
关于node.js - Github个人访问 token 在nodeJS中的api请求调用中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57385623/