首页 文章

Google观看次数 - 获取某个地区的照片详情

提问于
浏览
18

正在寻找一种模仿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>

我对 longitudelatitudetime takenuser 信息感兴趣 . 我看了Google places API但找不到方法 .

Update: 为了清楚起见,我在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
         },...

任何意见,将不胜感激 :)

1 回答

  • 9

    我有好消息和坏消息 . 好消息是,这是可能的,坏消息是有一些疯狂的警告,并且不能保证你能够获得你想要的每张照片的信息 .

    步骤1:用户信息

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

    {
      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步:查找照片

    现在,合乎逻辑的下一步似乎是谷歌API,但事实证明他们仍未提供访问谷歌照片的方法 . 令人惊讶的是,Picasa Web API仍然正常运行,似乎仍然可以返回最新数据 . 接下来我们可以使用上面找到的 userId 通过以下网址请求此用户的所有相册(Google已经使用相同的ID,或者仅支持Google用户ID) .

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

    在那里,用户拥有的每张专辑都有一个 <entry> ,其中包含以下内容

    <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 字段中的网址来请求每个相册Feed以获取照片列表 . 这将返回另一个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>
    

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

    结束

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

相关问题