The use of IP-based location services has increased day by day. We see that an IP geolocation API is used in many applications from almost every domain. The ipstack API, which is preferred by companies such as Microsoft and Samsung, is frequently used. Today, user satisfaction is the primary purpose of using IP geolocation APIs. Many businesses, therefore, use IP-based location services in conjunction with a Google News API.
There are many services to use with an IP geolocation API. Google News API is the most popular web service used with an IP geolocation API. There are many benefits to using these two together. In this article, we will first touch on these benefits. Then, we will develop a web application using the IP geolocation API and Google News API together in just a few steps.
Table of Contents
What are the Benefits of Using an IP Geolocation API and Google News API Together?
There are many benefits to using IP geolocation and Google News APIs (Application Programming Interfaces) together. Some of these benefits are as follows:
- Personalized Content: IP Geolocation API allows you to determine the user’s geographic location. Using this information, you can present geographically relevant news to the user. For example, if a user is in Turkey, you can bring news about Turkey.
- Content Focus: Combining the IP Geolocation API and Google News API allows users to focus on news relevant to their location. This can improve user experience and help you provide users with the latest happenings in their location.
- User Satisfaction: Once the user’s location is determined with the IP Geolocation API, you can focus on news that may interest users more. This can encourage users to visit your web application more often.
- Content Richness: Google News APIs provide access to current and diverse news sources. This allows you to offer users a wide range of news and can increase the richness of content. You can even offer local news articles and blog articles to your users thanks to this API.
- User Experience Improvement: Using the IP Geolocation API and Google News API together can help you customize and personalize the user experience. Users can access news most relevant to their geographic location.
Personalize a News Site Based on Visitor’s Location
In this section, we will use the ipstack API, one of today’s most popular IP geolocation APIs, together with the Zenserp API, the most equipped Google News API in the market. Before we start developing the application, let’s briefly get to know the Zenserp Google News API.
Zenserp Google News API is one of the most preferred news APIs in the market today. It is a SERP scraper API and its best job is to scrape SERP data from Google. Thanks to its powerful infrastructure, this API provides uninterrupted data flow to its users within seconds.
This API can provide users with geotargeted news results and news results based on a custom date range. In this respect, Zenserp API is suitable for global use. It also offers code samples from multiple programming languages in its innovative documentation and provides easy integration to developers. It provides API results in structured JSON format. Finally, it also provides error codes and every error message of each in its documentation.
Let’s use this Zenserp API and ipstack API together in a web application.
Get API Keys
To use these APIs in a web application, we need API keys for both of them. Let’s sign up for the free subscription plans offered by the ipstack API and Zenserp API and obtain API keys.
Code
After obtaining the API keys, we can now continue with the code development part. Our purpose in this web application will be to obtain location information with the ipstack API when the visitor enters the application and lists the Google News results in the visitor’s location on the page.
To do this, let’s open an HTML file and put the following codes into it:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Latest Soccer News in Turkey Location</title>
<!-- Bootstrap CSS link -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h1 id="location">Fetching Location...</h1>
<div class="card">
<div class="card-body">
<h3>News</h3>
<ul id="news-list"></ul>
</div>
</div>
</div>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<!-- Application JavaScript -->
<script>
// Use the ipstack API to get the user's location
const ipstackAPI = "http://api.ipstack.com/check?access_key=IPSTACK-ACCESS-KEY";
// API key and base URL for Zenserp API to fetch news
const zenserpAPIKey = "ZENSERP-ACCESS-KEY";
const zenserpBaseURL = "https://app.zenserp.com/api/v2/search";
// Select HTML elements
const locationElement = document.getElementById("location");
const newsListElement = document.getElementById("news-list");
// Call ipstack API to get the user's location
fetch(ipstackAPI)
.then((response) => response.json())
.then((data) => {
const country_code = data.country_code;
const locationText = `Latest Soccer News in ${data.country_name} Location`;
locationElement.textContent = locationText;
// Call Zenserp API with the country code to get news
const zenserpURL = `${zenserpBaseURL}?apikey=${zenserpAPIKey}&q=soccer&tbm=nws&hl=${country_code}`;
return fetch(zenserpURL);
})
.then((response) => response.json())
.then((data) => {
const newsResults = data.news_results.slice(0, 5); // Get the first 5 news
// Add the news to the list
newsResults.forEach((result) => {
const li = document.createElement("li");
const link = document.createElement("a");
link.textContent = result.title;
link.href = result.link;
link.target = "_blank";
const source = document.createElement("span");
source.textContent = ` - ${result.source}`;
li.appendChild(link);
li.appendChild(source);
newsListElement.appendChild(li);
});
})
.catch((error) => {
console.error("Error:", error);
locationElement.textContent = "Location Not Available.";
});
</script>
</body>
</html>
Test
After completing the code part, we can now move on to the testing phase. Before running our application, let’s put our API keys in the ‘IPSTACK-ACCESS-KEY’ and ‘ZENSERP-ACCESS-KEY’ fields and run the application.
After running the application, we got the latest news about ‘Soccer’ in our location:
Conclusion
Personalizing a news site based on a visitor’s location is a highly effective way to improve user experience and make content more engaging. Locating a visitor using the IP geolocation API allows you to direct them to news relevant to their area. This allows users to access more relevant and personalized content, which can increase user satisfaction and increase the likelihood of repeat visits to the website.
Sign up today and experience the best Google Search Scrape API features!
FAQs
Q: Is Zenserp a Free Google News Search API?
A: Yes, it is. Zenserp offers Google News API users a free plan with up to 50 API calls per month.
Q: Why Should I Use ipstack API and Zenserp Google News API Together?
A: The advantage of using ipstack API and Zenserp Google News API together is to determine the geographical location of the user and personalize and present news appropriate to this location. While ipstack is used to detect the location of the visitor, access to news specific to this location is provided with the Zenserp Google News API.
Q: Does Zenserp API Integrate With All Programming Languages?
A: Yes, it does. Developers can integrate this API into any programming language in just a few steps.
Q: Which Products From Google Does the Zenserp API Support?
A: Google products supported by Zenserp API are as follows:
- Google Search
- Google Image Search
- Google Video Search
- Google Maps Search
- Google News Search
- Google Shopping Search
- Google Trends