我需要将从 google place 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 不允许在您的服务器上保存图像。
关于php - 将 google place api 照片保存到我的服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37944572/