Mar 5, 2010

FixWire News API

So one of the other services that we wanted to provide on our group project was a local news service so I picked the FixWire API to do this. Documentation for the AP can be found Here. This API requires two steps. First you will need to find the Geo (as FixWire calls it) which is a location ID for all of the locations throughout the us. The URL for doing this is:

http://api.fwix.com/general/geos.xml

This provides the following output:



Once you have this output you can get the geoId for the locations that you want to search. From there you will need to provide three things for the search. The GeoID, a latitude and a longitude. You then form this into a url which will look like the following:

http://api.fwix.com/fetch/nearby.xml?geo_id=117&lat=34.2257255&lon=-77.9447102&radius=3

You will get an output that looks something like this:



I then took this data and parsed it using SimpleXML and Xpath methods to extract the stories and the data that I needed. I did it using a series of for loops and then formatted it using HTML in the PHP script before it was sent back to the Javascript. Here is the code:




What I did here was to create a function that grabbed only the first 250 characters of a story and then I checked to see if the XML had a image tag. If it did then I printed different HTML that included the image. Then I just went to a for loop to print out all the stories with their title, summary, and source, as well as the picture if it had one. Here is the final output.

No comments:

Post a Comment