如何使用google-gdata .net API通过Picasa从ID获取单张照片

时间:2010-10-26 16:48:43

标签: c# .net gdata-api picasa

我正在尝试使用.net API库从Picasa通过ID获取单个图片。

到目前为止,我试图通过以下方式找到正确的电话:

  • 新照片();但是没有构造函数的参数来告诉它要获得哪张照片
  • new Entry();与上述相同
  • PicasaQuery.CreatePicasaUri;但我必须指定albumId然后,我没有。

我似乎也无法在API文档中找到对此的REST调用(我可以完全绕过.net API)。

我当然用谷歌搜索了这个,但是似乎没有人希望通过ID获得单个图像,或者我错过了明显的(或者这是疯狂的场景......)。

2 个答案:

答案 0 :(得分:0)

CreatePicasaUri方法有三种变体,其中一种接受照片ID。你是对的,你需要专辑ID,但你应该能够获得它。

获取相册列表及其相关信息(请注意,我使用名为MyAlbum的结构存储相册中的所有照片信息,以便稍后在我的代码中使用):

        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

根据照片ID进行查询:

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

答案 1 :(得分:0)

您写道:

  

我似乎也无法在API文档中找到对此的REST调用(我可以完全绕过.net API)。

我同意你的观点,the Google API documentation on Picasa没有明确说明。不是我看到的。

但是,做一个GET https://picasaweb.google.com/data/feed/api/user/<userid>/albumid/<albumid>/photoid/<photoid>

在该GET请求中至少需要2个标头:Authorization和GData-Version。查阅文档以查看这些标头需要保留的内容。

照片的典型请求如下:

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

典型的回答如下:

<?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>