php - 将 google place api 照片保存到我的服务器

标签 php google-maps google-places-api

我需要将从 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/

相关文章:

php - 自动递增 UPDATE 查询 ID 或序列号

android - 使用 Google Maps API for Android 搜索位置

android - 谷歌地图仅显示空白图 block android

android - 如何在 Google Places API 中获取特定国家/地区的结果以在 Android 中进行自动完成预测?

database - 如何使用自己的位置数据库在网络应用程序中进行基于位置的搜索

google-maps - Google Maps API-Radius是否使用Places搜索标记?

php - 如何显示即将到来的生日?

php - 我不知道如何在使用 jquery 删除记录时获取记录的 ID

php - 选择 Paypal 服务

android - 更新 Google Play 服务后应用程序才会运行