Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 从天气API向Twitter机器人获取数据_Node.js_Json - Fatal编程技术网

Node.js 从天气API向Twitter机器人获取数据

Node.js 从天气API向Twitter机器人获取数据,node.js,json,Node.js,Json,我正在设置一个推特机器人来推特一个城市的温度,我得到了API,但我似乎无法将它挂在我的bot.js文件上 我试图改变变量,但似乎没有任何效果 var Twit = require('twit'); var config = require('./config'); var T = new Twit(config); gotData(); function setup() { loadJSON("http://api.apixu.com/v1/curre

我正在设置一个推特机器人来推特一个城市的温度,我得到了API,但我似乎无法将它挂在我的bot.js文件上

我试图改变变量,但似乎没有任何效果


var Twit = require('twit');

var config = require('./config');
var T = new Twit(config);


 gotData();


     function setup() {

         loadJSON("http://api.apixu.com/v1/current.json?key=7165704df08340e9b00213540192507&q=Colombo", gotData);

    }


    function gotData(data) {
        console.log('Weather Data Retrieved...')

    var r = data.current[2];

    var tweet = {
      status: 'here is ' + r + ' temperature test '
    }

    T.post('statuses/update', tweet);

}
TypeError:无法读取未定义的属性“current”

gotData()
的调用未传递
data
参数,因此当
gotData
函数尝试访问
数据时,当前[2]
数据
未定义。根据代码的外观,您只需更改行
gotData()
设置()

替换gotData();设置();