I have some problems using async/await. If i call getAccountDetails
i only get undefined
and afterwards i get the log
getOpengraphResponse
is ok
But i use async/await. And request is request-promise-native
. At position one should be the log
getOpengraphResponse
is ok
and then the property details
should be displayed. Where is my mistake?
const https = require('https');
const request = require('request-promise-native');
let openGraphBaseURL = "https://graph.facebook.com//v3.1/";
class Account{
constructor(name){
this.name = name;
}
}
class InstagramAccount extends Account{
async getAccountDetails(EdgeID, token){
this.EdgeID = EdgeID;
this.token = "&access_token=" + token;
this.command = this.EdgeID+"?fields=name,username,website,biography,followers_count,follows_count,media_count,profile_picture_url"+this.token;
this.details = await this.getOpengraphResponse(this.command);
console.log(this.details);
}
getOpengraphResponse(command){
request.get({
url: openGraphBaseURL+command,
json: true,
headers: {'User-Agent': 'request'}
}, (err, res, data) => {
if (err) {
console.log('Error: ', err);
}else if (res.statusCode !== 200) {
console.log('Status:', res.statusCode);
} else {
console.log('getOpengraphResponse is ok');
return data;
}
});
}
}