github API 不支持的媒体类型 415

wha*_*les 3 api http github github-api meteor

我在 Meteor 中使用 github API 但无法解决这个问题:

此代码尝试获取某个 repo 的总流量。

HTTP.call( 'GET', 'https://api.github.com/repos/hackmdio/hackmd/traffic/views', 
    {
        headers: 
        {
            'Content-Type':'application/json',
            "Accept":"application/vnd.github.v3+json",
            "User-Agent": "whales"
        },
    },
    function( error, response ) {
  if ( error ) {
    console.log('---------------------------error occurred-----------------------------------')
    console.log('---------------------------error occurred-----------------------------------')

    console.log( error );
  } else {

    console.log('--------------------------data got it!!-------------------------------------')
    console.log('--------------------------data got it!!-------------------------------------')

    console.log(response);
  }
});
Run Code Online (Sandbox Code Playgroud)

错误:

{
  "message": "If you would like to help us test the Repo Traffic API during its preview period, you must specify a custom media type in the 'Accept' header. Please see the docs for full details.",
  "documentation_url": "https://developer.github.com/v3"
}
Run Code Online (Sandbox Code Playgroud)

我搜索了类似的问题并添加了“Content-Type”和“Accept”,但它仍然无法正常工作。

然后我尝试在 Postman 和具有相同标头的终端中执行此操作,但此错误不断发生。 在此处输入图片说明

非常感谢。

kfb*_*kfb 6

您需要Accept: application/vnd.github.spiderman-preview在请求中添加一个标头,以便在预览形式下访问 Repo Traffic API。来自API 文档

用于存储库流量的 API 目前可供开发人员预览。在预览期间,API 可能会更改,恕不另行通知。有关完整详细信息,请参阅博客文章。

要访问 API,您必须在 Accept 标头中提供自定义媒体类型:

application/vnd.github.spiderman-preview

  • 此外,如果有人正在使用仍在开发人员预览中的任何其他功能,最好使用此概述页面 https://docs.github.com/en/rest/overview/api-previews 选择正确的值 - 我正在使用项目我必须选择“application/vnd.github.inertia-preview”。 (3认同)