2016-09-05 2 views
1

Я использую GitHub API в Метеор, но не смог решить эту проблему:GitHub API неподдерживаемый тип средств массовой информации 415

Этот код пытается получить общее количество трафика в течение определенного репо.

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); 
    } 
}); 

Ошибка:

{ 
    "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" 
} 

Я искал подобные вопросы и добавил "Content-Type" и "Accept", но это все еще не работает.

Я тогда попытался сделать это в Postman, а также в терминале с теми же заголовками, но эта ошибка продолжалась. enter image description here

Большое спасибо.

ответ

1

Вам нужно будет добавить заголовок Accept: application/vnd.github.spiderman-preview к вашему запросу, чтобы получить доступ к API трафика Repo, пока он находится в форме предварительного просмотра. От API docs:

APIs for repository traffic are currently available for developers to preview. During the preview period, the APIs may change without advance notice. Please see the blog post for full details.

To access the API you must provide a custom media type in the Accept header:

application/vnd.github.spiderman-preview

Смежные вопросы