How to create a news binder on your site

The presence of new updated content is a determining factor for the success of a site. Creating and updating the content constantly is, however, not an easy operation and not without costs.

Among the things that can be done with the use of Google Api, there is to provide our site with one or more news collectors, through research and publication of RSS feeds made available by the most disparate sites. By resorting to the search engine loader, we can read a number of news, videos and blog comments based on a geographic location, etc.

In short, we can enrich the home page with fresh news from any area, area or date.

How to create a news binder on your site

Clicking on a specific feed leads to a Google page (Add to Google) where it is possible to use the green link to be used as a parameter to be passed to the Google API search function.

We ask Google for a key

In order to use the Google APIs, you must have a Google account (Gmail is fine too) and go to the registration area at the address, and type the address relative to the page where we want to exploit the API. We thus obtain an alphanumeric key 86 characters long to be used in the script that we must implement to create our news container.

Together with the key, the service also provides a script, to be used on the page where we want to collect the news, with which to search and publish news, videos and comments based on geographical location.

How to create a news binder on your site

Let's examine the code provided

Let's focus on the code of the OnLoad () function:

function Onload(){

// Create a search control
var searchControl=new

// add a full set for search (web, video, blog)
var localSearch = new;


// Establish a geo-referenced location for the search
localSearch.setCenterPoint(“New York,NY”);

// Tell Google the name of the page element (usually a

that greases from container

// Perform the search

// Make the function call (Ajax)

We can see how, with a few instructions, we have obtained the main body of a potential script to be used to create a news container.

A custom container

In addition to geo-referenced search, there are other ways to use Google APIs to collect news. For example, we can ask the engine to read the content of a feed of a specific topic and published on a particular site. Let's see below how to conceive a script, to be implemented in an Html page or inside a container, to be used on our home page to enrich it with interesting and always fresh news.

We can use as a starting point, the header of the script contained in the email, making use of our API-Key:

“type=”text javascript”>

If we access our Google account through an SSL connection, we must use the Https protocol instead of Http. The second tag:


Make the call to the Google API in their version 1.

The heart of the Script

Let's analyze the main function of the script, which we are going to conceive. We can call her Onload() as in the example provided with the API Key. The following line of code:

var attributes=["title","link","publishedDate","contentSnippet"];

Defines the attributes of the published feeds that the Google engine will have to collect and return to our search, the title, the link to the content, the publication date, the summary (see box Lo standard Rss). The line:

var RSSfeed = new google.feeds.Feed(“”)

Create a container that we initialize, through the method = new google.feeds.Feed to which we pass, as a parameter, the address where the feed we are interested in is located.

With code

RSSfeed.setNumEntries (3);

We ask the engine to return the first three results, which are returned via the call:



How to create a news binder on your site

A container for the results

The display of the news must necessarily take place within an element of the page where the script resides. An element is generally used for this purpose :

var container=document.getElementById(“RSSfeed”);

The name entered (RSSfeed) is the Id that we must assign, through an appropriate tag, to the element that acts as a container (for example ).

We organize the News

The completion of the search occurs through the creation of a cycle (for (var i = 0; i <result.feed.entries.length; i ++)), based on the value previously set for the number of results, within which we must collect and organize the information fished by the engine. Through the method document.createElement we declare variables that we will need for the construction of the Html code, generated by the script, necessary to view the news. Generating this code is done with the method appendChild of each variable.

The use of the Google API takes place through an Ajax call (google.setOnLoadCallback(OnLoad)) to which we pass the name of the main function of the script as a parameter.


function On Load(){

var attributes=[“title”,”link”,”publishedDate”,”contentSnippet”];
var RSSfeed=new google.feeds.Feed(“”);
RSSfeed.setNumEntries (3);


var container=document.getElementById(“RSSfeed”);

for (var i = 0; i

add a comment of How to create a news binder on your site
Comment sent successfully! We will review it in the next few hours.