【问题标题】:Google views - get photos details for a regionGoogle 视图 - 获取某个地区的照片详细信息
【发布时间】:2015-05-19 18:05:27
【问题描述】:

寻找一种方法来模仿 Flickr API 逻辑以使用 Google 视图。

在 Flickr 上,我可以调用 flickr.photos.search 方法并获取特定位置的所有照片,如下所示:

https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=cb33497ccae3482a7d5252f15b790fe3&woe_id=727232&format=rest&api_sig=bc7b1227243d969498f9d7643438f18f

回应:

<?xml version="1.0" encoding="utf-8" ?>
  <rsp stat="ok">
    <photos page="1" pages="7673" perpage="100" total="767266">
    <photo id="17856165012" owner="91887621@N04" secret="6d2acf3b87" server="7690" farm="8" title="Amsterdam Canal" ispublic="1" isfriend="0" isfamily="0" />
    <photo id="17830118816" owner="131827681@N05" secret="ee8b55fc5e" server="7756" farm="8" title="IMG_2209" ispublic="1" isfriend="0" isfamily="0" />
    <photo id="17668921970" owner="131827681@N05" secret="bd0061e638" server="8825" farm="9" title="IMG_2210" ispublic="1" isfriend="0" isfamily="0" />
    <photo id="17853550052" owner="131827681@N05" secret="c834e9a7eb" server="7738" farm="8" title="IMG_2212" ispublic="1" isfriend="0" isfamily="0" />
    <photo id="17856935911" owner="131827681@N05" secret="39be86bb4b" server="7723" farm="8" title="IMG_2213" ispublic="1" isfriend="0" isfamily="0" />
    <photo id="17233920844" owner="131827681@N05" secret="8be2333be3" server="7658" farm="8" title="IMG_2214" ispublic="1" isfriend="0" isfamily="0" />
    <photo id="17853542232" owner="131827681@N05" secret="8f19ee65c2" server="7747" farm="8" title="IMG_2215" ispublic="1" isfriend="0" isfamily="0" />
    <photo id="17856926911" owner="131827681@N05" secret="bc0fb6dbc1" server="7667"....

然后我为每个照片 ID 调用 flickr.photos.getInfo 以获取照片信息

回应:

<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
  <photo id="17853542232" secret="8f19ee65c2" server="7747" farm="8" dateuploaded="1432037570" isfavorite="0" license="0" safety_level="0" rotation="90" originalsecret="7848968317" originalformat="jpg" views="2" media="photo">
    <owner nsid="131827681@N05" username="trashhunters" realname="Trash Hunters" location="" iconserver="7748" iconfarm="8" path_alias="trashhunters" />
    <title>IMG_2215</title>
    <description />
    <visibility ispublic="1" isfriend="0" isfamily="0" />
    <dates posted="1432037570" taken="2015-05-17 13:47:32" takengranularity="0" takenunknown="0" lastupdate="1432040217" />
    <editability cancomment="0" canaddmeta="0" />
    <publiceditability cancomment="1" canaddmeta="0" />
    <usage candownload="1" canblog="0" canprint="0" canshare="1" />
    <comments>0</comments>
    <notes />
    <people haspeople="0" />
    <tags>
      <tag id="131822341-17853542232-563433" author="131827681@N05" authorname="trashhunters" raw="blikje" machine_tag="0">blikje</tag>
      <tag id="131822341-17853542232-81138" author="131827681@N05" authorname="trashhunters" raw="fanta" machine_tag="0">fanta</tag>
    </tags>
    <location latitude="52.367408" longitude="4.862769" accuracy="16" context="0" place_id="xQ4tawtWUL1NrOY" woeid="727232">
      <locality place_id="xQ4tawtWUL1NrOY" woeid="727232">Amsterdam</locality>
      <county place_id="nmbnjNtQUL_iOTHdPg" woeid="12592040">Amsterdam</county>
      <region place_id="F86XYCBTUb6DPzhs" woeid="2346379">North Holland</region>
      <country place_id="Exbw8apTUb6236fOVA" woeid="23424909">Netherlands</country>
    </location>
    <geoperms ispublic="1" iscontact="0" isfriend="0" isfamily="0" />
    <urls>
      <url type="photopage">https://www.flickr.com/photos/trashhunters/17853542232/</url>
    </urls>
  </photo>
</rsp>

我对经度纬度耗时用户信息感兴趣。我查看了Google places API,但找不到方法。

更新: 为了清楚起见,我在 Google API 上找到了 place details 请求,但照片结果不包含位置或用户数据:

..."photos" : [
         {
            "height" : 2322,
            "html_attributions" : [
               "\u003ca href=\"//lh5.googleusercontent.com/-QO7PKijayYw/AAAAAAAAAAI/AAAAAAAAAZc/fTtRm3YH3cA/s100-p-k/photo.jpg\"\u003eWilliam Stewart\u003c/a\u003e"
            ],
            "raw_reference" : {
               "fife_url" : "https://lh3.googleusercontent.com/-7mKc4261Edg/VB01Tfy2OWI/AAAAAAAADII/BHs-SIudu64/k/"
            },
            "width" : 4128
         },...

任何建议将不胜感激:)

【问题讨论】:

  • API 调用有点复杂。您按纬度/经度提出请求。您将获得一个地点或地点列表,具体取决于您对所寻找内容的具体程度。然后,您对图像进行 API 调用,然后对每个图像 URL 进行另一个 API 调用。
  • 我正在使用不需要 API 密钥 BC 的旧 API,API 密钥是特定于域的。新的 API 更好。但是,如果您要结束问题,我已经完成了 70%,但注意到您已经接受了答案。 LMK,如果您仍然愿意将实施作为答案或对当前答案感到满意。
  • 当然!我很高兴得到另一种方法,谢谢!
  • 您想要 Google 全景街景、当地地方的 G+ 照片,还是(我怀疑)两者兼而有之?您想要批量上传所有图片,还是逐个选择相关的图片?
  • 不,David Mulder 的回答是正确的。您想要的一切都可用,但确实无法访问图片标题、cmets 等 G+ 元数据。谷歌在过去一个月中发布了一些针对合并地图和 G+ 的主要版本,但他们要么没有得到提供此信息,或对此不感兴趣

标签: javascript api google-maps google-places-api flickr


【解决方案1】:

我有好消息和坏消息要告诉你。好消息是它是可能的,坏消息是有大量的警告,并且不能保证您能够获得每张照片所需的信息。

第一步:用户信息

当您从地点 API 请求地点信息时,您会收到一组照片。每张照片都有一个url、一个width、一个height和一个html_attributions字符串。如果我的理解是正确的,那么如果机构所有者自己上传了照片,最后一个字符串将为空,但如果是第三方内容,它将包含一个链接,您必须将其包含在带有用户属性的页面中。要使用您问题中 Google 总部的第一张照片,我们会获得以下信息

{
  url: 'https://lh5.googleusercontent.com/-7mKc4261Edg/VB01Tfy2OWI/AAAAAAAADII/BHs-SIudu64/s0/20140109_152438.jpg',
  width: 2322,
  height: 4128,
  html_attributions: '<a href="https://plus.google.com/107252953636064841537">William Stewart</a>'
}

在大多数情况下(如果不是全部),这将是指向 Google Plus 用户帐户的链接,我们可以从中提取 userId。在这种情况下107252953636064841537

第 2 步:查找照片

现在,合乎逻辑的下一步似乎是使用 Google+ API,但事实证明他们仍然没有包含访问 Google+ 照片的方法。然而令人惊讶的是,Picasa Web API 仍然启动并运行,并且似乎仍然返回最新数据。所以接下来我们可以使用上面找到的userId,通过以下网址为该用户请求所有相册(Google 已经使用了相同的 ID,或者只是支持 Google+ 用户 ID)。

https://picasaweb.google.com/data/feed/api/user/107252953636064841537

对于用户拥有的每个专辑,都有一个 &lt;entry&gt;,其中包含以下内容

<feed>
   [...]
   <entry>
      [...]
      <link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="https://picasaweb.google.com/data/feed/api/user/107252953636064841537/albumid/6061059278861279377" />
      [...]
   </entry>
</feed>

您需要通过在href 字段中请求网址来请求每个相册供稿以获取照片列表。这将返回另一个 xml 文档,其中包含每张照片的以下信息:

<entry>
  <id>https://picasaweb.google.com/data/entry/api/user/107252953636064841537/albumid/6061059278861279377/photoid/6061059282579110242</id>
  <published>2014-09-20T08:05:33.000Z</published>
  <updated>2014-10-08T20:11:49.889Z</updated>
  <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/photos/2007#photo" />
  <title type="text">20140109_152438.jpg</title>
  <summary type="text" />
  <content type="image/jpeg" src="https://lh3.googleusercontent.com/-7mKc4261Edg/VB01Tfy2OWI/AAAAAAAADII/BHs-SIudu64/20140109_152438.jpg" />
  <link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="https://picasaweb.google.com/data/feed/api/user/107252953636064841537/albumid/6061059278861279377/photoid/6061059282579110242" />
  <link rel="alternate" type="text/html" href="https://picasaweb.google.com/107252953636064841537/September20201402#6061059282579110242" />
  <link rel="http://schemas.google.com/photos/2007#canonical" type="text/html" href="https://picasaweb.google.com/lh/photo/CpdWkfaimetJbSbFK2cojdMTjNZETYmyPJy0liipFm0" />
  <link rel="self" type="application/atom+xml" href="https://picasaweb.google.com/data/entry/api/user/107252953636064841537/albumid/6061059278861279377/photoid/6061059282579110242" />
  <link rel="http://schemas.google.com/photos/2007#report" type="text/html" href="https://picasaweb.google.com/lh/reportAbuse?uname=107252953636064841537&amp;aid=6061059278861279377&amp;iid=6061059282579110242" />
  <gphoto:id>6061059282579110242</gphoto:id>
  <gphoto:version>7</gphoto:version>
  <gphoto:position>2.0</gphoto:position>
  <gphoto:albumid>6061059278861279377</gphoto:albumid>
  <gphoto:access>public</gphoto:access>
  <gphoto:width>4128</gphoto:width>
  <gphoto:height>2322</gphoto:height>
  <gphoto:size>1756108</gphoto:size>
  <gphoto:client />
  <gphoto:checksum />
  <gphoto:timestamp>1389241477000</gphoto:timestamp>
  <gphoto:imageVersion>3202</gphoto:imageVersion>
  <gphoto:commentingEnabled>true</gphoto:commentingEnabled>
  <gphoto:commentCount>0</gphoto:commentCount>
  <gphoto:streamId>cs_01_3c7bd15d390e38745feedfd0c8ec076f</gphoto:streamId>
  <gphoto:license id="0" name="All Rights Reserved" url="">ALL_RIGHTS_RESERVED</gphoto:license>
  <gphoto:shapes faces="done" />
  <exif:tags>
     <exif:fstop>2.2</exif:fstop>
     <exif:make>SAMSUNG</exif:make>
     <exif:model>GT-I9505</exif:model>
     <exif:exposure>0.030303031</exif:exposure>
     <exif:flash>false</exif:flash>
     <exif:focallength>4.2</exif:focallength>
     <exif:iso>80</exif:iso>
     <exif:time>1389281077000</exif:time>
     <exif:imageUniqueID>721da79fdf344aa70000000000000000</exif:imageUniqueID>
  </exif:tags>
  <media:group>
     <media:content url="https://lh3.googleusercontent.com/-7mKc4261Edg/VB01Tfy2OWI/AAAAAAAADII/BHs-SIudu64/20140109_152438.jpg" height="288" width="512" type="image/jpeg" medium="image" />
     <media:credit>William Stewart</media:credit>
     <media:description type="plain" />
     <media:keywords />
     <media:thumbnail url="https://lh3.googleusercontent.com/-7mKc4261Edg/VB01Tfy2OWI/AAAAAAAADII/BHs-SIudu64/s72/20140109_152438.jpg" height="41" width="72" />
     <media:thumbnail url="https://lh3.googleusercontent.com/-7mKc4261Edg/VB01Tfy2OWI/AAAAAAAADII/BHs-SIudu64/s144/20140109_152438.jpg" height="81" width="144" />
     <media:thumbnail url="https://lh3.googleusercontent.com/-7mKc4261Edg/VB01Tfy2OWI/AAAAAAAADII/BHs-SIudu64/s288/20140109_152438.jpg" height="162" width="288" />
     <media:title type="plain">20140109_152438.jpg</media:title>
  </media:group>
</entry>

注意&lt;content&gt; 标记的src 属性如何等于第一个API 调用中的url,除了您应该忽略的子域(由于负载平衡而不同)。另请注意有关照片的所有可用信息如何在 xml 文档中公开,以及它如何包含已从照片本身剥离的所有 exif 数据。显然,并非所有照片都包含 GPS 信息,上面一张就是其中的一个例子。但是,如果照片确实包含 GPS 信息,它将包含在该文档中的 exif 数据和/或 &lt;georss:where&gt; 标签中。

结束

要找到您要查找的信息,您需要遍历所有用户相册,然后搜索与您从 Google Places API 收到的照片具有相似 url 的照片。最大的警告是,它只适用于来自 Google+ 的照片,它需要 大量 请求,而且 Picasa Web API 可能会在某个时候停止,尽管在那个时候至少它的部分功能将被移植到 Google+ Photos API(尽管 Google 计划再次移植到 make Google Photos a standalone service,所以在这种情况下它可能只是被重命名)。无论哪种方式,所有人都认为我很惊讶它是可能的,因为 Google Place API 并不是为所有这些而设计的,所以从这个意义上说,我猜你很幸运。

【讨论】:

  • 感谢您的努力,仍然缺少一步:获取某个地区的所有照片。知道该怎么做吗?
  • @ShlomiSchwartz 啊,好吧,Picasa Web API 不提供这样的功能,所以在这种情况下,我猜你有两个选择:通过 API 抓取所有 Picasa 网络相册或查询地点来构建自己的索引通过 Google Places API,然后按照描述检索相关照片。在第二种情况下,有一个相对简单的nearbysearch API 调用或在 javascript API 中的PlaceSearchRequest
  • 抱歉,此信息不正确。他们实际上已经允许访问照片。 API 调用有点棘手。首先,您必须选择特定地点,然后您会收到详细信息请求,然后为每张照片调用 API。这是我用来创建 Plunker 的过时 API。新的 API 要好得多,但它需要一个特定于域的密钥。
  • @DaveAlperovich 请更清楚,哪些信息不正确?谁允许访问哪些照片?您希望对每张照片执行哪个 API 调用? Plunker 应该是什么?
  • 关于其余的:我实际上做了所有的 API 调用。您认为我在哪里找到了我在答案中引用的相关回复?唯一的区别是我手动完成了所有处理,这些处理将在最终实现中编写脚本。我确实找到了有关问题中提到的照片的要求信息,并且我描述了每一个步骤,以允许自动查找该信息。第一次我只是通过网络界面做的,后来我通过 Place API 和 Picasa Web API 找到了相同的信息。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-03
  • 1970-01-01
  • 2017-05-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多