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

发布于 2024-09-29 13:56:43 字数 361 浏览 4 评论 0原文

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

到目前为止,我尝试通过以下方式找到正确的调用:

  • new Photo();但没有构造函数参数告诉它要获取哪张照片
  • new Entry();与上面相同
  • PicasaQuery.CreatePicasaUri;但我还必须指定 albumId,但我没有。

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

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

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...).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

剧终人散尽 2024-10-06 13:56:43

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

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))
罗罗贝儿 2024-10-06 13:56:43

你写道:

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

我同意您的观点,Picasa 上的 Google API 文档没有明确说明。不是我看到的。

但是,执行 GET 操作
https://picasaweb.google.com/data/feed/api/user//albumid//photoid/

您至少需要 2 个标头在该 GET 请求中:授权和 GData 版本。请查阅文档以了解这些标头需要保存什么。

典型的照片请求如下所示:

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/"CEQGR385eyp7ImA9Wx9REU0."'>
  <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&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>

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/"CEQGR385eyp7ImA9Wx9REU0."'>
  <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&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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文