我正在使用 probot => https://probot.github.io/
我一直在开发一个 GitHub 应用程序,用于分析存储库中的特定 .json
文件以了解日期字符串的更改。
我通过订阅 push
事件并使用 webhook
观看它来做到这一点。
我在 Node.js 中使用 request
。我遇到的问题是,当 Hook 运行时,我不断收到 404
。我的代码如下所示:
app.on('push', async context => {
let repoOwner = context.payload.repository.owner.name;
let repoName = context.payload.repository.name;
const options = {
url: `https://api.github.com/repos/${repoOwner}/${repoName}/contents/file.json`,
headers: { 'User-Agent': 'request' }
}
request.get(options, (error, response, body) => {
console.log(body) // logs {message: 'Not Found', documentation_url:... etc
})
})
之前我没有包含一个 user-agent
header ,它不断返回 403
- GitHub 的 api 指定您必须传递一个 header 。执行此操作后,我现在不断收到此 404
最佳答案
404 的可能原因:
- 存储库是私有(private)的,您无权访问(这需要 header
“Authorization:token $TOKEN”
) - JSON 响应(自 the default answer is a JSON with the file contents encoded in base64 起)超过 1MB。 Get Contents API确实提到“此 API 支持最大 1 MB 的文件。”
使用 header “Accept: application/vnd.github.3.raw
”将为您提供原始内容。
关于node.js - GitHub API - "Get contents"持续返回 404 有效路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59505491/