I am trying to make a request with the request package and can't seem to be able to pass through a simple parameter.
Anyone know what would be the best way to pass it through?
asyncRefreshToken()
.then(function(token){
console.log('Got the token! ' + token);
for(var k=0; k<2; k++){
var url= 'https://www.googleapis.com/analytics/v3/data/realtime?ids=ga:'+brandsConfig.brands[k].profileId+'&metrics=rt%3AactiveUsers&dimensions=rt%3ApagePath&sort=-rt%3AactiveUsers&access_token='+token;
var options = {
url: url,
method: 'GET'
}
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
// Print out the response body
var parsed = JSON.parse(body);
var activeUsers = parsed.totalResults;
console.log(brandsConfig.brands[k].title + ': ' + activeUsers);
}
})
}
})
Sorry, I should be more specific - brandsConfig.brands[k].title will only return the last value i.e. brandsConfig.brands[1].title
What I am trying to achieve:
Once a token has been obtained (from asyncRefreshToken), use the request package to query the Google Analytics API for a list of brands.
The brands are in an array brandsConfig.brands[k], the corresponding title can be obtained from brandsConfig.brands[k].title
The result for now, during the time I'm trying to learn can just be in the console.
So ideal result:
* Got the token! 1234567890 * Brand 1 : 582432 * Brand 2 : 523423
Current output:
* Got the token! 1234567890 * Brand 2 : 582432 * Brand 2 : 523423