newsAPI

FREEMIUM
(Ким) Strata Consulting LLC | Оновлено il y a 2 mois | News, Media
Популярність

9.7 / 10

Затримки

1,259ms

Рівень обслуговування

100%

Health Check

N/A

Назад до всіх навчальних посібників (3)

How do I use topic id's?

In newsAPI, the topicId has two main uses. The first is to find news articles within a general topic or category (like “Sports” or “Entertainment”), and the second is to find articles related to a news story like “Hurricane Lee Live Updates”

The /topic endpoint in newsAPI requires topicId's, which are hashed strings generated by Google News. If you are looking for a general category of news, there are only a few instances where you can provide an actual word for the topic. These are:

  • Latest
  • World
  • Business
  • Technology
  • Entertainment
  • Science
  • Sports
  • Health

For example, a request for the topic “Business” like GET https://newsapi90.p.rapidapi.com/topic/business will work, but if you were looking for the topic “Politics”, and you tried this: GET https://newsapi90.p.rapidapi.com/topic/politics it will not work. This is because you need to use the hashed topicId for the topic “Politics”.

So how do you find the topic id for a general category of news?

If you are looking for a general category’s topic id for something like “Climate Change” or “Electric Cars”, then you can go to news.google.com and search for that topic. In the suggestions drop-down of the search bar, some items will be labeled as “Topic”. Click on the one you want (Note: it MUST be labeled as a “Topic”). After you click on it, look at the URL navigation bar in your web browser and copy all of the text between “topics/” and the first question mark ("?").

For example, if the URL looks like this:

https://news.google.com/topics/CAAqIggKIhxDQkFTRHdvSkwyMHZNR1F3TmpOMkVnSmxiaWdBUAE?hl=en-US&gl=US&ceid=US%3Aen

Then you want to copy this part:

CAAqIggKIhxDQkFTRHdvSkwyMHZNR1F3TmpOMkVnSmxiaWdBUAE

That is your topicId that you can use with the /topic endpoint in newsAPI. For example, you can now search like this:

GET https://newsapi90.p.rapidapi.com/topic/CAAqIggKIhxDQkFTRHdvSkwyMHZNR1F3TmpOMkVnSmxiaWdBUAE

And the result should be a list of news articles about the topic you chose.

Using the topic id to find articles related to a news story

The topicId is also useful if you want to search for articles related to a specific news story, not just a general category. When you get data back from newsAPI, many of the articles will have a topicId property. You can use this topicId to search for articles that are related to that specific news story.