处理谷歌照片引用以获取图像url

问题描述:

我使用node.js并使用照片引用字符串并希望获得对返回的图像的访问权限。处理谷歌照片引用以获取图像url

我有下面的代码,正在取回正文中的东西。

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。但是我得到的是代表网页的对象。

任何帮助将不胜感激。

+0

你想要保存图像,还是只需要在网上获取图像的网址? –

+0

例如:从[此API调用(https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=CmRdAAAAHcsAE2aiv5lIxLEo0c9xMUmH-chXoAeq6yrFPw5uy7LdppAMxBmg8_yvG9y9qaXqsH-IrcPsBD6QQvsfZnpml3U5zgh93nTbm5WONnYmutBSltIr9FwuK-awm8l1vyKeEhD9AqZpJwFLIWms2GeZGPR2GhSPp1JyAU_6_s1Im1_oH5tB4IjyXQ&key=API-KEY)到这个[图像URL] (https://lh3.googleusercontent.com/-B8FWOhhu2_k/VTdYJeFjRhI/AAAAAAAAAD8/JSJamjx4XyA/s1600-w400/) –

+0

@RohinGopalakrishnan我只是想图像网址在线 – user1907509

根据documentation获取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控制台上启用结算功能,您可以免费增加此限制,每24小时可处理多达150,000个请求。

希望这有助于您!