bzarras / newsapi

A promise-based node interface for NewsAPI
MIT License
144 stars 39 forks source link

NewsAPIError: parametersIncompatible #13

Closed ihorbond closed 6 years ago

ihorbond commented 6 years ago

Tried to get news with the following example from official website

const NewsAPI = require('newsapi');
const newsapi = new NewsAPI('7bfd3e755d524648883ebae00d2280f7');

newsapi.v2.topHeadlines({
  sources: 'bbc-news,the-verge',
  q: 'bitcoin',
  category: 'business',
  language: 'en',
  country: 'us'
}).then(response => {
  console.log(response);
  /*
    {
      status: "ok",
      articles: [...]
    }
  */
});

but keep getting error 'You cannot mix the sources parameter with the country or category parameters'. When I remove sources I don't get any articles back. node version 9.11. running on local express server

bzarras commented 6 years ago

@ihorbond Thanks for pointing this out. The example usage of the v2.topHeadlines is misleading in that it demonstrates that sources, country, and category are available parameters to pass, but according to the official NewsAPI top-headlines docs, country and category can not be used simultaneously with sources.

I would guess that the reason you got no articles back after removing sources is that there simply were no recent top headlines that were categorized as "business" and contained the query "bitcoin".

I will update my usage examples to address this. I recommend to always refer to the official NewsAPI docs when looking for which parameters are valid and what kind of values they accept.

bzarras commented 6 years ago

Examples updated. Closing issue.

petersamoaa commented 5 years ago

@bzarras Hi, the problem still appear, I mean for instance top_headlines = newsapi.get_top_headlines(q='bitcoin', sources='bbc-news,the-verge', category='business', language='en', country='us') still doesn't work due to the error message (cannot mix country/category param with sources param. )

heshamelmasry77 commented 5 years ago

I don't know why the object doesn't have the category of the news!! very weird api

destinysam commented 3 years ago

@ihorbond Thanks for pointing this out. The example usage of the v2.topHeadlines is misleading in that it demonstrates that sources, country, and category are available parameters to pass, but according to the official NewsAPI top-headlines docs, country and category can not be used simultaneously with sources.

I would guess that the reason you got no articles back after removing sources is that there simply were no recent top headlines that were categorized as "business" and contained the query "bitcoin".

I will update my usage examples to address this. I recommend to always refer to the official NewsAPI docs when looking for which parameters are valid and what kind of values they accept.

ThankYou

nh303 commented 3 years ago

Can you please update the document, so that no new developer finds these issues again? It will be really helpful.

Thank You

Zia-Saeed commented 1 year ago

After removing source from the code I am getting the results