php – 保存谷歌将api照片放到我的服务器上

我需要将从google places API返回的图像保存到我的服务器.

我试过了 :

$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));

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

我正在使用PHP编写代码.

任何帮助都会很棒

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

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不允许在服务器上保存图像.

点赞