推文流错误SyntaxError:意外的令牌E nodejs

时间:2015-04-10 21:23:06

标签: javascript node.js twitter

我试图用nodejs获得一个流推特应用程序,显然一切都很好但是当我用应用程序打开超过2页时我得到了这个错误:

SyntaxError: Unexpected token E
at Object.parse(native)
at EventEmitter.receive(C: \Program Files\ nodejs\ node_modules\ twitter\ lib\ pa rser.js: 40: 21)
at IncomingMessage. < anonymous > (C: \Program Files\ nodejs\ node_modules\ twitter\ lib\ twitter.js: 207: 14)
at IncomingMessage.emit(events.js: 117: 20)
at IncomingMessage. < anonymous > (_stream_readable.js: 765: 14)
at IncomingMessage.emit(events.js: 92: 17)
at emitReadable_(_stream_readable.js: 427: 10)
at emitReadable(_stream_readable.js: 423: 5)
at readableAddChunk(_stream_readable.js: 166: 9)
at IncomingMessage.Readable.push(_stream_readable.js: 128: 10)

//server
var Twitter = require('twitter');
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var PORT = process.env.PORT || 8080;


var client = new Twitter({
  consumer_key: '',
  consumer_secret: '',
  access_token_key: '',
  access_token_secret: ''
});
app.get('/', function(req, res) {

  res.sendFile(__dirname + '/indext.html');
});
var i = 0;
io.on('connection', function(socket) {
  client.stream('statuses/filter', {
    track: 'colombia'
  }, function(stream) {
    stream.on('data', function(tweet) {
      console.log(tweet.text);
      i++;
      socket.emit('message', tweet.text, i);


    });
    stream.on('error', function(error) {
      throw error;

    });

  });
});

http.listen(PORT, function() {
  console.log('listening on %s', PORT);
});

//client

var socket = io();
$(function() {


  socket.on('message', function(msg, n) {
    $("#listamsg").append($('<br><div style="background-color:#1947A3; 

color:white;font-family:Arial; width:700px;">').text(msg));
    
    $("#num").text(n)
    $("#container").animate({
      scrollTop: $("#container")[0].scrollHeight
    });

  });

});

0 个答案:

没有答案