保存谷歌将api照片保存到我的服务器 [英] Saving google places api photos to my server

查看:111
本文介绍了保存谷歌将api照片保存到我的服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将从google places API返回的图像保存到我的服务器。
我试过:

i need to save the images returned from the google places API to my server. I've tried :

$url= 'https://maps.googleapis.com/maps/api/place/photo?key=API_KEY_HERE&photo_reference=CoQBcwAAAAtXfnhO3WCagOlY4p4Px7N8Pcks_N-cLbMQzruT-AdWRZoyJgABVUUcuZ_4bbcUdReloBl2zGd80W4E4w-N_kyab4xz4S3ZZIRVECCJP1u7JsXOfxEsx4XQbL-HeMBRKzNul0XSdy-Dv4495i_8-SqYqTBZMaLvn1YLaVM3aAzOEhBgLV4lpKeM39L6gb9wBbU6GhSmCkYp8djpm9_iaqkS93z4ekLnNg&maxheight=200'

$target = md5($array['result']['photos'][0]['photo_reference']);
$newname = 'img/googlephotos/newimage'.$target;
file_put_contents($newname,file_get_contents($url));

但它不起作用 - 当它保存时它会保存一个空文件而不是图像 - 我认为它缺少文件扩展名,但我不知道如何获得它。有谁知道保存谷歌地方照片的任何方法?

But it's not working - when it's saving it saves an empty file and not the image - I think it is missing the file extension but I'm not sure how to get it. does anyone know of any ways to save google places photo?

我用PHP编写我的代码。

I'm using PHP to write my code.

任何帮助都会很棒

推荐答案

您应该了解服务条款中的限制。特别是,第10.5(d)段说:

You should be aware of the restrictions in Terms of Service. Particularly, paragraph 10.5 (d) says:


您不会预取,缓存,索引或存储任何要在外部使用的内容本服务,但您可以存储有限数量的内容,仅用于提高由于网络延迟而导致的Maps API实施的性能(而不是为了阻止Google准确跟踪使用情况),并且仅限于此类存储:
是临时的(在任何情况下都不超过30个日历日);是安全的;
不会操纵或汇总内容或服务的任何部分;和
不会以任何方式修改归因。

You will not pre-fetch, cache, index, or store any Content to be used outside the Service, except that you may store limited amounts of Content solely for the purpose of improving the performance of your Maps API Implementation due to network latency (and not for the purpose of preventing Google from accurately tracking usage), and only if such storage: is temporary (and in no event more than 30 calendar days); is secure; does not manipulate or aggregate any part of the Content or Service; and does not modify attribution in any way.

https://developers.google.com/maps/terms#10-license-restrictions

此时看起来ToS不允许在服务器上保存图像。

At this point it looks like the ToS doesn't allow saving images on your server.

这篇关于保存谷歌将api照片保存到我的服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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