Google places retrieve photo gets 301 redirect when trying to display

99封情书 提交于 2019-12-11 05:55:51

问题


This is frustrating the hell out of me!

I have retrieved a json from google places search api. I have retrieved the photo_reference and used it to get the photo like so

echo  '<img src="https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference='.$photo_reference.'&key='.$apikey.'"/>';

I get nothing visible in the browser. When i view source i have the html for the images there. If i put the href directly into the url bar it shows me the picture that in the documentation means that I have exceeded my quota. You can see here if you scroll down to "Place Photo Response" in this link to google docs

The thing is that I haven't exceeded my quota. I go to my Google API dashboard and go to quotas and it clearly says at this moment in time i have only made 19 queries. I can still query the places API no problem. I have to to get the photo reference.

So what the hell am I missing? All I can find is documentation of people who can work out how to parses the response but nothing about quotas.


回答1:


Any one else having this problem... Check to see if you have specified IP restrictions in your control panel. I have restricted the API access to my server but then when i was trying to display the image front end without caching the image server side first, of course the front end IP address (the users IP) is different to the server ip which is white listed. So to fix this, cache the image server side then display it, or remove the IP white list from the Google dev control panel.




回答2:


The "out of quota" image may also be caused by access to the Places API being denied, based on IP or referrer restrictions on your API key.

You would normally want to have an IP restriction on the API key you use for the Places API web service, so that it can only be used from your server. The same key cannot be used for the IMG tags, because requests will come form users' browsers, and be denied. You can create a separate API key, restricted to your site/s (referer/s) and use that in the IMG tags.



来源:https://stackoverflow.com/questions/38705159/google-places-retrieve-photo-gets-301-redirect-when-trying-to-display

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!