node.js - Github个人访问 token 在nodeJS中的api请求调用中不起作用

标签 node.js api github

尝试在调用 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/

相关文章:

git - 当开发尚未稳定时将错误修复推送到生产中

node.js - 在 Electron 中,fs 操作是在 ipcRenderer 或 ipcMain 中完成的

javascript - 在 node.js 中捕获 tshark stdout 输出

facebook - 如何使用 facebook api 从群组中获取待售帖子

python - 使用 urllib2.urlopen 时获取 "TypeError: unhashable type"

android - Gradle无法解决github依赖

git - 你如何从历史 github 提交中删除或更改你的 git user.name?

javascript - 使用回调 Javascript 在多个函数中获取多个数据

javascript - 如何为 Sequelize 模型设置外键?

Android:在使用 Retrofit 继续执行之前等待 API 的响应