gpt4 book ai didi

javascript - 处理 google photo reference 获取图片 url

转载 作者:搜寻专家 更新时间:2023-10-31 23:59:33 25 4
gpt4 key购买 nike

我正在使用 node.js 并拥有照片引用字符串,并且想要访问返回的图像。

我有以下代码,正在找回 body 里的东西。

  locations.forEach(function(loc) {
var photoRef;
if (loc.photos && Array.isArray(loc.photos)) {

photoRef = loc.photos[0].photo_reference;

var url_in = 'https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=' + photoRef + '&key=' + key;

request(url_in, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body); // Show the HTML for the Google homepage.
}
});


}

});

我只想获取作为图像 url 的字符串。但我得到的是一个代表网页的对象。

如有任何帮助,我们将不胜感激。

最佳答案

您无法根据 documentation 获取图像 url因为 API 不返回 url。

https://lh3.googleusercontent.com/-B8FWOhhu2_k/VTdYJeFjRhI/AAAAAAAAAD8/JSJamjx4XyA/s1600-w400/

你的 image url 然而已经是

imageurl = 'https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=' + PHOTO_REFERENCE + '&key=' + API_KEY;
// ^^^ this would return the image for you already (hence, your image url)

您可以在每 24 小时内将此图片网址用于 1,000 个免费请求。通过在 Google API 控制台上启用计费,您可以免费增加此限制,每 24 小时最多 150,000 个请求

希望这对您有所帮助!

关于javascript - 处理 google photo reference 获取图片 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40572232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com