Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google views - get photos details for a region

Looking for a way to mimic Flickr API logic to use Google views.

On Flickr I can call the flickr.photos.search method and get all the photos for a specific location like so:

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

The response:

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

Then I call flickr.photos.getInfo for each photo id to get the photo info

The Response:

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

I'm interested in the longitude, latitude, time taken and user info. I've looked through the Google places API but couldn't find a way.

Update: just to be clear, I've found the place details request, on Google API but the photos result does not contain location or user data:

..."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
         },...

Any advice would be appreciated :)

like image 620
Shlomi Schwartz Avatar asked May 19 '15 18:05

Shlomi Schwartz


People also ask

Where do Google images come from?

The satellite and aerial images in Google Earth are taken by cameras on satellites and aircraft, which collect each image at a specific date and time.

How do I see my photos on Google Maps?

Here's how to use it: Open Google Photos app and tap on the “Search” tab at the bottom. Here you should find the “Explore Map” feature in the second section, tap on it to open it. This will open a map of your current location with heat patterns on the map where you have taken your photos.


1 Answers

I have good news and bad news for you. The good news is that it's possible, the bad news is that there are a crazy amount of caveats and it's not guaranteed you will be able to get the info you wish for every photo.

Step 1: The user information

When you request place information from the place API you receive an array of photos. Each photo has an url, a width, a height and a html_attributions string. If my understanding is correct that last string will be empty if the owner of the establishment uploaded the photos himself, but in case it is third party content it will contain a link which you have to include in the page with user attribution. To use the first photo for Google HQ from your question we get the following information

{
  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>'
}

In the large majority of the cases (if not all) this will be a link to a Google Plus user account, from which we can extract the userId. In this case 107252953636064841537

Step 2: Finding the photo

Now, the logical next step would seem to go to the Google+ API, but it turns out that they still have not included a way to access Google+ Photos. Surprisingly enough however the Picasa Web API still is up and running and seems to still return up to date data. So next we can request all albums for this user through the following url using the userId we found above (Google has kindly used the same ids, or simply supports Google+ user ids).

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

In there there is a single <entry> for each album the user has which contains the following

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

You would need to request every album feed to get a list of photos by requesting the url in the href field. This will return another xml document which contains the following information for each photo:

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

Note how the src attribute of the <content> tag is equal to the url from the first API call, except for the sub domain which you should ignore (which is different because of load balancing). Also note how all available information about the photo is exposed in the xml document and how it contains all exif data which has been stripped from the photo itself. Obviously not all photos contain GPS information, and the above one is an example of that. If however a photo does contain GPS information it will be included in that document either in the exif data and/or in a <georss:where> tag.

Concluding

To find the information you're looking for you would need to loop through all the users albums and then search for a photo with a similar url to the one you received from the Google Places API. The biggest caveats are that it will only work for photos from Google+, that it requires a lot of requests and that the Picasa Web API is likely to be discontinued at some point, though at that point at least a part of its functionality will be ported to the Google+ Photos API (though Google is planning again to make Google Photos a standalone service, so in that case it might just be renamed). Either way, all considered I am surprised that it is possible at all as the Google Place API isn't made for all this, so in that sense you're quite lucky I guess.

like image 58
David Mulder Avatar answered Oct 03 '22 01:10

David Mulder