Monday 11 February 2019

javascript - Returning undefined value - Node.js

I have the below function which correctly takes from the response the prefix and the suffix of the image and makes a variable result,which holds the url of the venue image. However when i return the result, i keep having undefined.What is going wrong here?






function getPhotoUrl(venue_id,venue_location,venue_query){
request({
url: 'https://api.foursquare.com/v2/venues/'+venue_id+'/photos',
json:true,
method: 'GET',
qs: {
client_id: 'my_id',
client_secret: 'my_secret',
near:venue_location,

query: venue_query,
v: '20171114',
limit: 1
}
}, function(err, res, body) {
var result="";
if (err) {
console.error(err);
} else {
console.log(body.response.photos.items[0].prefix+"300x500"+body.response.photos.items[0].suffix);

}
result=body.response.photos.items[0].prefix+"300x500"+body.response.photos.items[0].suffix;
return result;
}
);
}



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...