Tip:
Highlight text to annotate it
X
>>
MAWSON: Hi, my name is Sven Mawson and I work on a Google Data APIs team. In this video,
I'm going to introduce you to the Picasa Web Albums Data API which gives you the ability
to access and manipulate the data stored within the Picasa Web Album service. This data includes
items such as albums, photos, comments and tags. I'm also going to show some examples
of the cool things you can do with the API. In case you haven t used it yet, Picasa Web
Album is Google's free photo sharing site that allows you and your family and friends
to quickly and easily share photos with each other and with the world. You can create albums
of photos to share with your family or friends, tag your photos or add geographic information
and add comments to photos so the authors know what you think and you can do all of
this with the API too. If you're in a hurry and wanted to just jump right in, go to code.google.com
to check out the documentation and get started. There are three ways that developers typically
interact with the API; first, by using the API to view and explore existing photos that
you or others have uploaded; second, by uploading new photos or creating new albums; and third,
by editing your own photos in photo metadata. First off, let's look at how to view a list
of albums for a user, here is the URL you would use to access a user's albums. I'll
break the URL down into parts because most of the URLs stay the same between requests.
The first part of the URL, picasa.web.google.com/data, is the base of the API and is always the same
for all Picasa Web Albums API requests. The second part of the URL selects the collection
type used for the request. The collection type is either feed entry or media, but in
our initial examples, we'll only be using the feed collection type. I'll discuss the
other collection types later on in the video. The third part of the URL is the projection
which identifies what subset of data to return. In our examples, we'll be using either the
base projection which is used for a read-only HTML view of that data or the API projection
which includes all the metadata and is used for read/write API access. The final part
of the URL is the context. This identifies what resource on the server you are interacting
with. In this example, we're interacting with an individual user, so the context includes
just the username. We'll see some of the other context in a minute. For all the query details
on URL format and additional options such as query priority numbers, please visit the
reference guide. Retrieving the list of photos in that album is very similar to retrieving
the list of a user's albums. We just take our existing URL and add one of our album
IDs like this. Here's an example response with much of the data removed to make it easier
to display. The photos come back in the entry elements with each photo entry containing
all of the metadata about a photo including information such as the dimensions of the
photo, thumbnail URLs useful for embedding in a webpage, a list of the tags, the photo
captions and more. Another common use of the API is to make it easy to access photo search
results. By using the all context and adding a query string, you can search for all kinds
of photos across your community search results. For example, you can search your photos tagged
with dog in Paris by adding Paris as the Q parameter and dog as the tag parameter like
this. If we use the base projection and enter this query into a browser that understands
atom feeds, usually, it we'll get back. There are many other search options such as adding
a geographic bounding box to search for results in a particular area or limiting the search
results to photos from your favorites or even from an individual user or album. All of the
search options are documented in the reference guide. So now let's take a look at an example
use of the album in photo feeds, BookSmart application by Blurb. So here we are inside
the BookSmart application by Blurb. And this allows us to use the Picasa Web Albums to
stay at the API to import photos into the application, which we can do by clicking on
the get photos button up here and choose in Picasa Web Albums. Now we just enter our username
and password and it'll use client log in to connect to Picasa Web Albums and download
your photos. First, it loads up all the photos in all the albums but then we can choose a
particular album that we set up earlier with some images of Einstein in it and then we
click select all and just click download and it imports those photos directly into the
application. You can see on the left the images and we can just drag and drop them right into
the book. This is the title page so we put a nice little picture of Einstein there and
then we choose the back page and add a different image and we can make ourselves a--another
book and print it up. While it s great to be able to view existing photos and search
for interesting content, we also want to be able to upload new photos. To do this we just
post the data we want to send to an appropriate feed URL. The easiest choice for uploading
is to just use the drop box, which is the default album that new photos go into when
uploaded. To upload to the drop box, you can either post the image to the user URL or post
image with album URL, with album IDs set to default, like this. You can also choose exactly
which album to upload to by using the albums ID in the URL. In addition to deciding what
album to post the image to, you also need to decide how to format the request. There
are currently two choices for upload format, you can either post the photo bytes directly
to the selected URL or you can post to both binary data and XML metadata using a single
mime multipart related request. If you are sending just the image bytes make sure to
set the content type header to the appropriate type. You can check out the list of supported
types in the reference guides. You can also optionally set a slug header which allows
you to set the title of the image. If you want to send both the image bytes and the
image metadata in the same request, you'll need to create a multipart related request
and post that to the URL. Here's an example of a multipart related request which sets
the title and caption of the photo at the same time as the photo is uploaded. Once again
you can check out the full details in the reference guide. I'm going to quickly walk
you through an example of uploading a photo using the Java client library. The other client
library is of similar capabilities and as always you can do all of this directly using
HTTP and XML. The first thing we do is create a Picasa web service object and then we call
the set user credentials method on it which will handle all the authentication handshaking
using client log in. You may also choose to use the off server or off authentication mechanisms
which are also fully supported by the client libraries. You can view a complete list of
available authentication mechanisms by going to code.google.com/api/accounts. Now that
we are authenticated, we need to pick an album to upload to. To do this we call the getfeed
method on the service object with the URL we're trying to retrieve, which in this case
is the list of albums URL which I spoke about earlier. Once this method has executed we
get back a feed object that we can use to get a list of album entries which we can then
present to our user to allow them to choose the upload destination. From the album entry,
we can get a link to the album feed location which tells us where to post new images, then
we just create a media file source using a local file and call the insert method on the
service object with the destination URL and the media source. The image will be uploaded
and a photo entry will return to us with the new photos ID and other metadata. This example
uses the direct posting method in posting the image bytes. But using the client library
to post a multipart related body is just as easy. So now we've seen how to view our existing
albums and photos and how to upload new photos, but what about editing our photos? This is
also easily accomplished using the API; to modify an image just put the new image bytes
to the edit media link that was returned from the last get or post to that photo. The edit
media link will look something like this; notice that the collection type here is media
to let the service know that you want to edit image bytes directly. In addition to updating
the photo bytes sometimes you want to update the photo metadata such as the photo's caption,
title or text. You can do this through the normal edit links, putting either just the
new metadata or a multipart related body containing both the new metadata and the new image bytes.
The URL to use for updating this content is very similar to the URL for updating just
the image bytes but with entry as a collection type instead of media. Now let's take a look
at a great application that uses the edit features of the API, picnic.com. This application
also uses the other capabilities I discussed earlier including retrieving list of albums
and photos and uploading new ones. So here we are inside picnic.com and we've already
used the picnic's interface with Picasa Web Albums to import our photos. So I've loaded
up a picture of Einstein here in the edit view, were going to go to the create view
to make some modifications to it. You can see all the tools on the left side there that
the picnic lets you use. What we're going to do is we're going to pick the tint tool
to change Einstein's color. Let's make him purple, so we choose the color and then we
choose a mode. We can choose hard light there and then we added a little fading and click
apply. And we have a nice purple Einstein. So now we actually want to save Einstein back
up to Picasa Web Albums, so we're going to give him a caption and then we can actually
choose to save a new file. And this uses the upload API; it actually sends multipart related
to include both metadata and the original image bytes at once. So now it's all done.
And if we go over to Picasa Web Albums we can actually refresh the page and see a--see
the new image. So there we go, you see our new image and our new caption right there.
So we can go back to picnic and make some more changes to this. Let's go ahead and make
Einstein neon instead of just purple and actually, let's make him neon green because that's a
nice color, and click apply, and we go back to the save and share tab. We're going to
change the caption, but this time we're actually going to save it in place of the old file
rather than as a new one. So it actually makes us confirm that we want to do that and we
click okay, and it saves the image back up to Picasa Web Albums. So if we go back and
hit refresh we can see the new image. All right, so by now I'm sure you're busy coming
up with the next great application that uses the Picasa Web Album data API. There are a
lot of things that I didn't cover, so for more information please check out the developer
guide and the rest of the documentation at code.google.com. You can also visit us in
the forum to ask question or to show off what you've created. Thanks and happy coding.