how process response object from Google Places API - placesPhoto

寵の児 提交于 2020-01-02 14:03:41

问题


I am writing a simple wrapper in node.js which calls Goole Places API and gets a photo using photo_reference. When I run this and process the request from Postman it works but does not display photo itself. In the code below mapsClient.placesPhoto does return a huge response with many tags. Its not just raw image data. My question is how do I extract image or image data from googleResp object and send it back to client?

var googleMapsClient = require('@google/maps').createClient({
  key: 'xyz' 
});

app.post('/getGooglePlacePhoto/:photoref', function(req, res){

    googleMapsClient.placesPhoto({
        photoreference: req.params["photoref"],
        maxwidth: 70,
        maxheight: 70
    }, function(err, googleResp){
        if (!err) {
            debug('got response from google');
            res.set('Content-Type','image/jpeg');
            debug(googleResp.body);
            res.send(200, googleResp.body);
        } else {
                debug(err);
                res.send(409, err);
                return;
        }

    });
});

来源:https://stackoverflow.com/questions/39508823/how-process-response-object-from-google-places-api-placesphoto

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!