I'm using the Twitter API as follows:
...
var params = {id: 656958};
client.get('trends/place', params, function(error, tweets, response){
if(error) throw error;
console.log(tweets[0]);
});
...
my Console log looks like this:
Console output
Now i want to store every name with the tweet_volume in a database.
How can I access these key/value pairs?
Thanks for your help!
I tried it like this:
var params = {id: 656958};
client.get('trends/place', params, function(error, tweets, response){
if(error) throw error;
console.log(tweets[0]);
});
var tweets = JSON.parse(tweets[0]);
function getNamePair(){
for (var key in tweets.trends) {
var name = tweets.trends[key].name;
var volume = jsonResponse.trends[key].tweet_volume;
console.log(key, "Name - " + name + ", tweet_vol - " + volume);
}
}
getNamePair();
But I got the error:
var tweets = JSON.parse(tweets[0]);
^
TypeError: Cannot read property '0' of undefined
By using var tweets = JSON.parse(tweets); I think i access the wrong data. Output in this case:
undefined:1
undefined
^
SyntaxError: Unexpected token u
sudo node top_hashtag.js > ~/output.txt. It will write the output to the file in you home dir.