簡體   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