繁体   English   中英

Twitter API“ twit”获取热门趋势,但无法使用

[英]Twitter api “twit” fetching top trends but unable to use it

首先,感谢您的帮助。

当我尝试获取特定区域的热门趋势时。 对于以下代码:-

var Twit = require('twit');
var config = require('./config');
var T = new Twit(config);
var params = {
    id: '1'
    // count: 3
}
T.get('trends/place', params, gotData);

    function gotData(err, data, response) {
        var tweets = data;
        console.log(tweets);
    }

我期待这样的数据(单击并转到示例响应)

但是我得到了这样的回应

C:\Users\Yash\IdeaProjects\yash>node bot3.js
[ { trends:
     [ [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object] ],
    as_of: '2018-01-25T14:59:11Z',
    created_at: '2018-01-25T14:54:58Z',
    locations: [ [Object] ] } ]

如果有人可以帮助我解决此问题,我将不胜感激。 我对node.js非常陌生。 这是用于大学项目的,但我仍然坚持。

您想要将返回的JSON对象转换为字符串进行显示,因此可以使用(例如) console.log(JSON.stringify(tweets, undefined, 2)); 要进行字符串化的第二个和第三个参数会使输出以更加可读的方式格式化。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM