As promised in the previous blog post, I was given the task of making our Chow Down Gdata sample a little faster. It would sometimes take a while to load restaurant information due to the requests to YouTube and Picasa Web Albums taking a while to be processed on the backend. Since this would cause the user to sometimes see a "loading" bar for several seconds; something had to be done.
As promised in the previous blog post, I was given the task of making our Chow Down Gdata sample a little faster. It would sometimes take a while to load restaurant information due to the requests to YouTube and Picasa Web Albums taking a while to be processed on the backend. Since this would cause the user to sometimes see a "loading" bar for several seconds; something had to be done.



Originally, the application used the Python client library to retrieve information from YouTube and PWA and then stored it inside of memcache. The new solution is to instead retrieves these feeds directly in the browser using the json-in-script support of the Google Data APIs. This approach worked well for the Chow Down application since we were not retrieving any private information for use in this application and so did not need to authenticate as a user.

Another benefit of using the JSON feeds is that the browser can asynchronously request results from both YouTube and PWA at the same time and render the results as soon as they are returned. This helps decrease the "perceived load time" that the user experiences since they are seeing information start to be loaded instead of just watching a progress bar.

The code for the entire sample is available on code.google.com:

http://code.google.com/p/gdata-samples/source/browse/trunk/chow-down-gdata/

But you can see all of the logic for retrieving the feeds using JavaScript in the ajax_restaurant_info template:

http://code.google.com/p/gdata-samples/source/browse/trunk/chow-down-gdata/src/templates/ajax_restaurant_info.html

The code makes use of the jQuery JavaScript library in order to remain compact and compatible.

So if your site is using the Data APIs of one or more Google properties and you don't need authentication, considering switching to the JSON feeds to improve perceived latency and let your pages load the AJAXy way.

Recently I was given the task of modifying the Chow Down sample application (originally written to demonstrate how to implement the Google FriendConnect API on Google AppEngine) to include videos, pictures and search results in the restaurant detail pages. This task resulted in the creation of ...
Recently I was given the task of modifying the Chow Down sample application (originally written to demonstrate how to implement the Google FriendConnect API on Google AppEngine) to include videos, pictures and search results in the restaurant detail pages. This task resulted in the creation of Chow Down Gdata (full source code) which uses the YouTube Data API, the Picasa Web Albums API and the AJAX Search APIs.


Since everything was written in Python, using our Python client library was a no brainer. The first step was to add the necessary files and import statements. The application follows a standard MVC layout, so the next step was to create a new view called JsonRestaurantInfoView in views.py, which I then connected both to the ajax_restaurant_info.htmltemplate and also to the restaurants_info method in providers/restaurants.py.

The bulk of the modifications happen inside restaurants_info:

# Create client and query to execute a YouTube search:
gdata_youtube_client = gdata.youtube.service.YouTubeService();
query = gdata.youtube.service.YouTubeVideoQuery()
query.vq = "%s %s" % (restaurant.name, restaurant.city)
video_feed = gdata_youtube_client.YouTubeQuery(query)

# Grab the URL to the embeddable Flash player SWF (if embeddable)
swf_url = video_entry.GetSwfUrl()

if swf_url:
restaurant.player = """<object width="425" height="350">
<param name="movie" value="%s"></param>
<embed src="%s" type="application/x-shockwave-flash"
width="425" height="350"></embed></object>""" %
(swf_url, swf_url)

But wait! We are not done yet. Let's also look for pictures for this restaurant in Picasa:
gdata_picasawebalbums_client = gdata.photos.service.PhotosService()
query_parameters = map(urllib.quote, [restaurant.name, restaurant.city]);

# Fetch a feed of 10 thumbnails, 32x32 pixels in size and cropped to a square
photo_feed = gdata_picasawebalbums_client.GetFeed(
"/data/feed/api/all?q=%s%%20%s&max-results=10&thumbsize=32c" %
(query_parameters[0], query_parameters[1]))

We store all the new metadata in the restaurant object that ends up being passed to the template. To direct users there from the search page, I added a simple show_restaurant_info function which is triggered when a user clicks on the restaurant title in the search listing. While I was in the templates/index.html file, I also added the ajax_api_restaurant_info function which fetches blog, web, news and book search information about the restaurant.

Check out the full source code to get the full picture including information about how this data was also cached.

In the next article, Jeff Fisher is going to talk about how to optimize the performance for this application by using JavaScript.

Enjoy a few new tidbits in the latest release.



Yup, the same way you can search for videos and channels , you can now use the API to search for playlists ...
Enjoy a few new tidbits in the latest release.

Search for playlists

Yup, the same way you can search for videos and channels , you can now use the API to search for playlists:
http://gdata.youtube.com/feeds/api/playlists/snippets?q=soccer&v=2
The query above will return a list of playlist snippets that match the query 'soccer'. Searching in playlists is an excellent way to find YouTube videos about a specific point of interest (e.g. dancing, cooking, sports etc.).

Time filtering for video search

You can now restrict the video search result to a specific time interval (today, this_week, this_month, all_time):

http://gdata.youtube.com/feeds/api/videos?q=soccer&time=today&v=2

The default is 'all_time'.

More results

You can now request past the 100th video in a playlist and past the 200th video in a favorite list. Additionally, you can now get 1000 videos in a search feed instead of 999! Enjoy that last video, guys.

As always, post in the forum if you have any feedback or questions!

Posted by Daniel Danciu, Software Engineer