开发者

How to get a single photo by ID from Picasa using the google-gdata .net API

开发者 https://www.devze.com 2023-01-21 06:42 出处:网络
I\'m trying to use the .net API library to get a single image by ID from Picasa. So far, I\'ve tried to find the correct call by doing:

I'm trying to use the .net API library to get a single image by ID from Picasa.

So far, I've tried to find the correct call by doing:

  • new Photo(); but there are no constructor params to tell it which photo to get
  • new Entry(); same as above
  • PicasaQuery.CreatePicasaUri; but I have to specify the albumId as well then, which I don't have.
开发者_如何转开发

I also can't seem to find the REST call for this in the API documentation (with which I could circumvent the .net API completely).

I've of course Googled this, but either nobody seems to want to get a single image by ID or I am missing the obvious (or this is a crazy scenario...).


The CreatePicasaUri method has three variations, one of which accepts a photo ID. You're right that you'll need the album ID but you should be able to obtain that.

To get a list of albums and their associated info (note that I use a structure called MyAlbum to store all of the photo info from the album for use later in my code):

        Dim username As String = "default"
        Dim query As AlbumQuery = New AlbumQuery(PicasaQuery.CreatePicasaUri(username))

        Dim feed As PicasaFeed = service.Query(query)
        Dim albums As New List(Of MyAlbum)

        For Each entry As PicasaEntry In feed.Entries

            Dim ac As AlbumAccessor = New AlbumAccessor(entry)
            Dim a As MyAlbum
            a.Name = ac.AlbumTitle
            a.ImageCount = ac.NumPhotos
            a.ID = ac.Id
            albums.Add(a)

        Next

To query based on Photo ID:

Dim query As PhotoQuery = Nothing
query = New PhotoQuery(PicasaQuery.CreatePicasaUri(username, albumID, photoID))


You wrote:

I also can't seem to find the REST call for this in the API documentation (with which I could circumvent the .net API completely).

I agree with you, the Google API documentation on Picasa doesn't spell it out explicitly. Not that I saw.

But, Do a GET on https://picasaweb.google.com/data/feed/api/user/<userid>/albumid/<albumid>/photoid/<photoid>

You will need at least 2 headers in that GET request: Authorization and GData-Version. Consult the doc to see what those headers need to hold.

A typical request for a photo looks like:

GET https://picasaweb.google.com/data/feed/api/user/default/albumid/5549217276399652081/photoid/5549537235612315698 HTTP/1.1
GData-Version: 2
Authorization: GoogleLogin auth=..._4kdkpseUiUQaQovCNXoBd8rU8GzOHxaq5lHCzmJV4k9
Host: picasaweb.google.com

A typical response looks like:

<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:exif='http://schemas.google.com/photos/exif/2007' xmlns:gphoto='http://schemas.google.com/photos/2007' xmlns:media='http://search.yahoo.com/mrss/' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/&quot;CEQGR385eyp7ImA9Wx9REU0.&quot;'>
  <id>https://picasaweb.google.com/data/feed/user/7787221111/albumid/5549217276399652081/photoid/5549537235612315698</id>
  <updated>2010-12-11T21:18:46.123Z</updated>
  <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/photos/2007#photo'/>
  <title>CropperCapture[65].jpg</title>
  <subtitle>Uploaded by Cropper</subtitle>
  <icon>https://lh3.googleusercontent.com/_-Mw_MhEEB_U/TQPqtox5sDI/AAAAAAAAACk/X-hS1Mf534M/s288/CropperCapture%5B65%5D.jpg</icon>
  <link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://picasaweb.google.com/data/feed/api/user/7787221111/albumid/5549217276399652081/photoid/5549537235612315698?authkey=Gv1sRgCJrQ5qeYxISo5gE'/>
  <link rel='http://schemas.google.com/g/2005#post' type='application/atom+xml' href='https://picasaweb.google.com/data/feed/api/user/7787221111/albumid/5549217276399652081/photoid/5549537235612315698?authkey=Gv1sRgCJrQ5qeYxISo5gE'/>
  <link rel='edit' type='application/atom+xml' href='https://picasaweb.google.com/data/entry/api/user/7787221111/albumid/5549217276399652081/photoid/5549537235612315698/1?authkey=Gv1sRgCJrQ5qeYxISo5gE'/>
  <link rel='alternate' type='text/html' href='http://picasaweb.google.com/lh/photo/7GvE1ehluip3iQEQtMw4_sQJQ0GDj3dCNP33YlpCH6E'/>
  <link rel='self' type='application/atom+xml' href='https://picasaweb.google.com/data/feed/api/user/7787221111/albumid/5549217276399652081/photoid/5549537235612315698?start-index=1&amp;max-results=500'/>
  <generator version='1.00' uri='http://picasaweb.google.com/'>Picasaweb</generator>
  <openSearch:totalResults>0</openSearch:totalResults>
  <openSearch:startIndex>1</openSearch:startIndex>
  <openSearch:itemsPerPage>500</openSearch:itemsPerPage>
  <gphoto:id>5549537235612315698</gphoto:id>
  <gphoto:albumid>5549217276399652081</gphoto:albumid>
  <gphoto:access>private</gphoto:access>
  <gphoto:width>261</gphoto:width>
  <gphoto:height>283</gphoto:height>
  <gphoto:size>13685</gphoto:size>
  <gphoto:checksum/>
  <gphoto:timestamp>1292102326000</gphoto:timestamp>
  <gphoto:imageVersion>41</gphoto:imageVersion>
  <gphoto:commentingEnabled>true</gphoto:commentingEnabled>
  <gphoto:commentCount>0</gphoto:commentCount>
  <gphoto:license id='0' name='All Rights Reserved' url=''>ALL_RIGHTS_RESERVED</gphoto:license>
  <exif:tags>
    <exif:imageUniqueID>4d7f804c08d8b48a89ccbdfe92971a12</exif:imageUniqueID>
  </exif:tags>
  <media:group>
    <media:content url='https://lh3.googleusercontent.com/_-Mw_MhEEB_U/TQPqtox5sDI/AAAAAAAAACk/X-hS1Mf534M/CropperCapture%5B65%5D.jpg' height='283' width='261' type='image/jpeg' medium='image'/>
    <media:credit>User Name</media:credit>
    <media:description type='plain'>Uploaded by Cropper</media:description>
    <media:keywords/>
    <media:thumbnail url='https://lh3.googleusercontent.com/_-Mw_MhEEB_U/TQPqtox5sDI/AAAAAAAAACk/X-hS1Mf534M/s72/CropperCapture%5B65%5D.jpg' height='72' width='67'/>
    <media:thumbnail url='https://lh3.googleusercontent.com/_-Mw_MhEEB_U/TQPqtox5sDI/AAAAAAAAACk/X-hS1Mf534M/s144/CropperCapture%5B65%5D.jpg' height='144' width='133'/>
    <media:thumbnail url='https://lh3.googleusercontent.com/_-Mw_MhEEB_U/TQPqtox5sDI/AAAAAAAAACk/X-hS1Mf534M/s288/CropperCapture%5B65%5D.jpg' height='283' width='261'/>
    <media:title type='plain'>CropperCapture[65].jpg</media:title>
  </media:group>
</feed>
0

精彩评论

暂无评论...
验证码 换一张
取 消