This documentation is designed for people familiar with JavaScript programming and object-oriented programming concepts. There are many JavaScript tutorials available on the Web.
The Google NewsShow embeds a news slideshow on your page, letting your users see headlines and previews of Google News Search results, based on queries that you've selected. The NewsShow can be easily added to your page through the use of an iframe or you can call the classes directly for additional customization. Here is an example of the NewsShow in action:
To include the NewsShow in your page, you will utilize the Google AJAX API loader.
The common loader allows you to load all of the AJAX APIs that you need, including the NewsShow. You need to both include
the Google AJAX APIs script tag and call google.load("elements", "1", {packages : ["newsshow"]})
:
<script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("elements", "1", {packages : ["newsshow"]}); </script>
The first script tag loads the google.load
function, which lets you load individual Google APIs.
google.load("elements", "1", {packages : ["newsshow"]})
loads Version 1 of the
NewsShow element. Currently we're in Version 1, but new versions may be available in the future. See the
versioning discussion below for more information. See an
example of how to load the NewsShow. Or, let our
wizard generate the code for you.
Normally, the language of the user interface will be chosen automatically by the system based on the value of the Accept-Language
http header. If this header is not present, a value of en
is assumed. However, if you wish to supply a different language,
you must do so while loading the NewsShow element. Replace the above
google.load("elements", "1", {packages : ["newsshow"]});
with this code:
var loadOptions = {packages : ["newsshow"]}; loadOptions.language = "en"; google.load("elements", "1", loadOptions);
Replace en
with your language of choice.
The second argument to google.load
is the version of the API you are using. Currently the we're in version
1, but new versions may be available in the future.
If we do a significant update to the API in the future, we will change the version number and post a notice on Google Code and the AJAX APIs discussion group. When that happens, we expect to support both versions for at least a month in order to allow you to migrate your code.
The AJAX API team periodically updates the API with the most recent bug fixes and performance enhancements. These bug fixes should only improve performance and fix bugs, but we may inadvertently break some API clients. Please use the AJAX APIs discussion group to report such issues.
This object implements the google.elements.NewsShow
interface which can display a series of news articles from the Google
News service, one after another.
Constructor | Description |
---|---|
|
The constructor is used to create an instance of a NewsShow object designed to provide and display search results from the Google News service. The only required parameter is "container", which instructs the NewsShow in which container to display the news articles. The method also accepts an optional parameter which controls the NewsShow's options.
|
Method | Description |
---|---|
|
This method is used to parse the NewsShow options out of a URL. If no URL is specified, the options will be
retrieved from the current document URL. Only options included in the URL are set (except for
|
The NewsShow can also be embedded onto your page using an iframe (as shown above). For example, place this code into the body of your webpage:
<iframe src="http://www.google.com/uds/modules/elements/newsshow/iframe.html?topic=e,p,s,n&rsz;=small" frameborder="0" width="728" height="90" marginwidth="0" marginheight="0"></iframe>
The second line contains some parameters adjusting the size and look of the iframe. The first line contains the URL from which to
access the NewsShow and some URL arguments to control its behavior. In some cases, an argument is optional. This is indicated with
a ? following the name of the argument. In all cases, the value of a CGI argument must be properly escaped (e.g., via the functional
equivalent of Javascript's encodeURIComponent()
method). This table lists the available URL arguments:
Argument | Example | Description |
---|---|---|
q | q=Paris%20Hilton | This argument supplies the query or queries used to generate the displayed result list. A comma separated list of URL encoded query values are allowed (e.g. &q;=hi,bye), as are multiple &q; args (e.g. &q;=hi&q;=bye). This argument or &topic; (see below) must be included with at least 1 value. |
topic? | topic=b |
This optional argument supplies the topic or topic used as a query to the News Search. The value of this argument specifies the
topic in the current or selected edition:
Topics vary slightly from edition to edition. E.g., in African editions like Namibia or Zimbabwe(&ned;=en_na, &ned;=en_zw) the topic af is available and represents the African topic. In general, if you are viewing an edition of Google News and see a topic of interest, click on the topic header and view the &topic; argument in the browser's address bar. |
rsz? | rsz=small |
This optional argument supplies the number of results that the application would like to recieve. A value of small
indicates a small result set size or 4 results. A value of large indicates a large result set or
8 results. If this argument is not supplied, a value of large is assumed.
|
ned? | ned=us |
This optional argument tells the NewsShow which edition of news to pull results from. Values include:
|
hl? | hl=en |
This optional argument supplies the host language of the application making the request. If this argument is not
present then the system will choose a value based on the value of the Accept-Language http header. If this
header is not present, a value of en is assumed. Note: This argument is not set with the method UrlToOptions.
|
format? | format=728x90 |
This optional argument specifies the dimensions of the NewsShow, valid values are:
728x90 is assumed.
|