Free html to display googles news to stories
Here is an example of free HTML code that you can use to display Google News stories on your website:
<!-- Google News Feed -->
<div id="google-news-feed"></div>
<script>
(function() {
var googleNewsFeed = document.getElementById('google-news-feed');
var googleNewsApiKey = 'YOUR_GOOGLE_NEWS_API_KEY'; // Replace with your own API key
var googleNewsQuery = 'TOP_STORIES'; // Replace with your desired query (e.g. "TOP_STORIES", "BUSINESS", etc.)
var googleNewsCount = 5; // Number of stories to display
var script = document.createElement('script');
script.src = 'https://www.google.com/jsapi';
script.onload = function() {
google.load('feeds', '1');
google.setOnLoadCallback(function() {
var feed = new google.feeds.Feed('https://news.google.com/news/feeds');
feed.setNumEntries(googleNewsCount);
feed.setQuery(googleNewsQuery);
feed.load(function(result) {
if (!result.error) {
var html = '';
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
html += '<h2>' + entry.title + '</h2>';
html += '<p>' + entry.contentSnippet + '</p>';
html += '<a rel="nofollow" target="_blank" href="' + entry.link + '">Read more</a>';
html += '<br><br>';
}
googleNewsFeed.innerHTML = html;
} else {
googleNewsFeed.innerHTML = 'Error loading Google News feed.';
}
});
});
};
document.body.appendChild(script);
})();
</script>
Here's how to use this code:
- Replace
YOUR_GOOGLE_NEWS_API_KEY
with your own Google News API key. You can obtain a free API key by creating a project in the Google Cloud Console and enabling the Google News API. - Replace
TOP_STORIES
with your desired query (e.g. "BUSINESS", "TECHNOLOGY", etc.). - Adjust the
googleNewsCount
variable to set the number of stories to display. - Copy and paste the code into your HTML file.
- Save the file and upload it to your website.
Note that this code uses the Google Feeds API, which is a free service that allows you to retrieve and display news feeds from Google News. However, the API has some limitations, such as a maximum of 100 requests per day and a requirement to display a link to the original news source. Be sure to review the Google Feeds API terms of service before using this code on your website.