Chapter 5. Location-aware News App — PacktNews

Hyperlocal applications and websites such as AOL's Patch.com provide precise and accurate news up to the neighborhood level, based on the user's location. In this chapter, we will learn to build a location-aware news application for Windows Phone 7.5—titled PacktNews — using AOL's Patch News API.

This chapter covers:

  • Understanding the Patch News API
  • Consuming the Patch News API — HelloNews
  • Building the PacktNews app using the Silverlight for Windows Phone 7.5 Pivot control

Understanding the Patch News API

AOL's Patch.com is a hyperlocal news portal that provides comprehensive and trusted local content to its users, and is powered by editors, writers, photographers, and videographers who live nearby.

Patch has a huge editorial team as well as freelance bloggers that help create original content, and which is published to a network of more than 850 sites. Patch local content includes news, events, business listings, photos, videos, and announcements. The geotagged hyperlocal content is available for third-party consumption via the Developer API at http://developers.patch.com/, which we will use to build our PacktNews app.

Before we move further towards building our app, lets us have a good look at the API calls provided by Patch.com and their structure. The Patch News API has the following four main components:

  • Authentication
  • Taxonomy (Categories)
  • Finding stories by location
  • Finding locations by name

Authentication

Any app or website that intends to use the Patch News API must obtain authentication. The authentication is a combination of your developer key, secret key and the current timestamp, all combined together and converted to a MD5 hash key. Unfortunately, the core platform for Windows Phone 7.5 does not support MD5 yet; however, there is a Silverlight MD5 implementation available from MSDN at http://archive.msdn.microsoft.com/SilverlightMD5 that we will use to perform the authentication for the Patch News API. The following is a snippet of code to get the MD5 hash via the MD5Managed class within a simple Windows Phone app:

public MainPage()
{
InitializeComponent();
string key = "xxxxxxxx";// Get key and secret from
//http://developers.patch.com/
string secret = "xxxxxxx";
inttimeInSecs = (int)(DateTime.UtcNow newDateTime(1970,
1, 1)).TotalSeconds;
MD5Managed md5 = newMD5Managed();
byte[] bs = System.Text.Encoding.UTF8.GetBytes(key + secret
+ timeInSecs);
byte[] hash = md5.ComputeHash(bs);
StringBuildersb = newStringBuilder();
foreach (byte b in hash)
{
sb.Append(b.ToString("x2").ToLower());
}
stringurl = "http://news-api.patch.com/v1.1/nearby/
37.785368,-122.441654/stories?dev_key=" + key +
"&sig=" + sb;
Debug.WriteLine(url);
}

Taxonomy

Patch organizes news stories into three main taxonomy types:

  • Vertical: Topic of the content
  • Format: Medium from which the content was found
  • Author type: Who wrote the content—an individual or a business

These taxonomies are further classified as:

  • Vertical:
    • News
    • Lifestyle
    • Education
    • Business
    • Science and technology
    • Sports
  • Format:
    • Stories
    • Reviews and ratings
    • Event listings
  • Author type:
    • Individuals
    • Businesses and organizations
    • Educational institutions
    • Government
    • Sharing and community sites
    • Independent news media
    • Mainstream media such as CNN and NY Times

Finding stories by location

The Patch News API supports location-based search for stories, by using any of the following parameters:

  • State
  • City
  • Zip code
  • Neighborhood
  • Nearby
  • Patch location universally unique identifier (UUID) (Patch.com internal city/state and neighborhood IDs), which can be retrieved by the find locations by name method described in the next section

Finding locations by name

Patch News API supports a location retrieval API call that accepts a text string and returns well-formatted location information, something similar to the GeoNames API and/or reverse geocoding.

The result of the query includes the UUID as discussed in the previous segment; this is useful if you are building an offline application, for example, an application for San Francisco city that uses the San Francisco UUID hardcoded in the application. Another use case would be to store content offline tagged with the UUID.

Locations to be queried could be any of the following parameters:

  • States
  • Cities
  • Zip codes
  • Neighborhoods
  • Places
  • Localities
  • Metro areas

Full documentation can be found at http://developers.patch.com/docs/.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.160.154