尝试显示时,Google地方信息检索照片会获得301重定向 [英] Google places retrieve photo gets 301 redirect when trying to display

查看:44
本文介绍了尝试显示时,Google地方信息检索照片会获得301重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这让我很沮丧!

我已经从Google Places Search API中检索了一个json.我已经检索了photo_reference,并用它来获取照片

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

我在浏览器中看不到任何内容.当我查看源代码时,我那里有用于图像的html.如果我将href直接放在网址栏中,则会显示文档中的图片表示我已超出配额.如果您在此链接到Google文档解决方案

基于IP或对API密钥的引用者的限制,超出配额"的图像也可能是由于拒绝访问Places API引起的.

您通常希望对用于Places API Web服务的API密钥进行IP限制,以便只能在您的服务器上使用它.不能将同一密钥用于IMG标签,因为请求将来自用户的浏览器,并被拒绝.您可以创建一个单独的API密钥,仅限于您的网站(引荐来源),并在IMG标签中使用它.

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.

解决方案

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.

这篇关于尝试显示时,Google地方信息检索照片会获得301重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆