Filtering the news api with categories
The News API!
Yes, you can filter the News API by categories. Here's how:
Method: GET /v2/top-headlines
Parameters:
country
: The country code (e.g., "us", "uk", "ca", etc.)category
: The category code (e.g., "business", "entertainment", "sports", etc.)q
: A search query (optional)
Example:
https://newsapi.org/v2/top-headlines?country=us&category=business&apiKey=YOUR_API_KEY
This will return the top headlines from the United States, filtered by the "business" category.
Available categories:
Here are the available categories you can use:
business
entertainment
general
health
science
sports
technology
You can combine multiple categories by separating them with commas:
https://newsapi.org/v2/top-headlines?country=us&category=business,entertainment&apiKey=YOUR_API_KEY
This will return the top headlines from the United States, filtered by both "business" and "entertainment" categories.
Note: Make sure to replace YOUR_API_KEY
with your actual API key from News API.