处理谷歌照片参考获取图像的url
我使用node.js并使用照片引用string,并希望访问返回的图像。
我有下面的代码,正在回到正文中的东西。
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的string。 但是我得到的是一个代表网页的对象。
任何帮助将非常感激。
根据文档 ,您不可能获取image url
,因为url不会被API返回。
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)
您可以使用这个图像url每24小时1000免费请求。 通过在Google API控制台上启用结算function,您可以免费增加此限制,每24小时可处理多达150,000个请求
希望这可以帮助!