title: Get Image URL From Google Places Photo API
body: <p>I am attempting to pull a photo URL from a request to the Google Places Api for a Rails application. I have been using the documentation located at: <a href="https://developers.google.com/places/documentation/photos#place_photo_response" rel="nofollow">https://developers.google.com/places/documentation/photos#place_photo_response</a></p>
  
  <p>The issue I'm running in to is that I'm getting an image as the return, not the URL itself. If I navigate by hand to the URL of the API request, I am redirected to a page containing the image. I am not sure how to access the URL that I am redirected to from my application. The code I am using is:</p>
  
  <pre><code>raw_rest = HTTParty.get("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=#{@lat},#{@long}&amp;radius=50000&amp;types=restaurant&amp;key=#{Rails.application.secrets.google_api_key}")
  
  
  @photo_reference = raw_rest["results"][0]["photos"][0]["photo_reference"]
  
  @photo = HTTParty.get("https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&amp;photoreference=#{@photo_reference}&amp;key=#{Rails.application.secrets.google_api_key}"
  </code></pre>
  
  <p>When I run this in the rails console, I can see that the return is an image (as the Google Places API says it will be). I'm not sure how to display the image without the URL, however. If there is a way in Rails to display an image saved to a variable, or a way to pull the redirect URL from HTTParty, that would be great.</p>
  
  <p>Thanks in advance! Let me know if there are any questions!</p>