avianflu / ntwitter Goto Github PK
View Code? Open in Web Editor NEWThis project forked from jdub/node-twitter
Asynchronous Twitter REST/stream/search client API for node.js
Home Page: https://github.com/AvianFlu/ntwitter
License: Other
This project forked from jdub/node-twitter
Asynchronous Twitter REST/stream/search client API for node.js
Home Page: https://github.com/AvianFlu/ntwitter
License: Other
Hello,
I'm being plagued by disconnects, the program keeps running but I get 0 entities from the twitter stream.
I already put down my error, end, close events to no avail.
There's a solution proposed here: https://github.com/iStrategyLabs/twitter-node/commit/3adc1686e2925fce16a416c3672bca3b9f507a7e
What do you think about it?
I suspect it might violate twitter rules about reconnecting as per documentation, but it can be a starting point.
Cheers
I see in the readme there is an example of how to publish a status update.
Is there any way to have a tweet look like a reply to a tweet from your stream, instead of just a plan status update?
Using this context:
NTwitter 0.2.7 on NodeJS 0.4.12 on 2.6.35.14-97.fc14.x86_64
NodeJS server crashes on
/usr/local/node/lib/node_modules/ntwitter/lib/twitter.js:204
Object.keys(params).forEach(function(item) {
^
TypeError: Object.keys called on non-object
at Function.keys (native)
at Twitter.stream (/usr/local/node/lib/node_modules/ntwitter/lib/twitter.js:204:10)
at s (**********************)
at Query. (/usr/local/node/lib/node_modules/mysql/lib/client.js:108:11)
at Query.emit (events.js:61:17)
at Query._handlePacket (/usr/local/node/lib/node_modules/mysql/lib/query.js:51:14)
at Client._handlePacket (/usr/local/node/lib/node_modules/mysql/lib/client.js:312:14)
at Parser. (native)
at Parser.emit (events.js:64:17)
at /usr/local/node/lib/node_modules/mysql/lib/parser.js:71:14
I "fixed it" using the old code...
if (Array.isArray(params)) {
params.forEach(function (item) {
params[item] = params[item].join(',');
});
}
Any idea of what's goin' on?
The createList method optionally takes a 3rd params object but checks to see if it is actually a callback function. If it is a callback function then params is set null. Later on, this null params value is passed to utils.merge and results in an error.
How can i use the site stream? Is it broke or working?
I don't get acces to it i'm receving 403 and node just stops.
hey this is really cool, but it would be even cooler if it supported the Stream
interface.
like, you could change this:
twit.stream('user', {track:'nodejs'}, function(stream) {
stream.on('data', function (data) {
console.log(console.dir(data));
});
// Disconnect stream after five seconds
setTimeout(stream.destroy, 5000);
});
to this:
twit.stream('user', {track:'nodejs'}).pipe(writable)
I'm also working on a toolkit for working with streams, https://github.com/dominictarr/event-stream that might have some useful examples.
Hi girls 'n guys, I'm having some [Error: socket hang up] code: 'ECONNRESET'
over here when trying to get the Favorites of about 280 Users at Heroku. Do you have a clue what's happening there? xD
Thanks :)
This is most valuable for rate limit errors. Currently, the error object when a client is rate limited is:
{ [Error: HTTP Error 400: Bad Request]
statusCode: 400,
data: '{"error":"Rate limit exceeded. Clients may not make more than 350 requests per hour.","request":"\\/1\\/lists.json?screen_name=JFSIII&cursor=-1"}' }
However, this doesn't inform the client when their limiting will end. That information is available via the X-RateLimit-Reset
header. The value is the UNIX timestamp when the limit will be lifted.
Even successful connections have useful information. Most notably X-RateLimit-Remaining
which informs the client how many calls are left before they get limited.
I'm just getting started with this library, so I don't have any suggestions for the preferred way to make them available. I only know that they are a requirement for clients. They are so important, I feel like I must have missed their inclusion. If so, I apologize for the noisy ticket and ask that you point me to the documentation or provide some example code.
I use nodejs-0.5.10 and here is my example.
As you may see, rss memory grows constantly. Just like heap memory. There may be nodejs bug, but may be your.
Also I have example with asyncjs queue for twitter requests (works faster), same effect there.
What do you think?
Why is line 105 of twitter.js:
callback(null, json);
Shouldn't is just be callback(json)? If you have a reason for this, you should probably outline it in the Readme, I had to read through the code to figure out why I was getting null results in my callback.
Tweets from this person: http://twitter.com/#!/Press24mk
Are displayed like so in the console:
TWEET: by Press24mk: ?????: ?????????? ???? ?? ?? ?????? ????? ????? | press24.m
k http://t.co/wi4Q5cnR
Is this related to this library, or my windows command line?
I'm using twitter-node for awhile but it discountinue ... So I decided to move my code to your lib :)
It work perfectly but I need feature that worked on twitter-node :p The track update list ie :
var TwitterNode = require('twitter-node').TwitterNode
, sys = require('sys')
var twit = new TwitterNode({
...
track: ['baseball', 'football'], // sports!
});
...
// adds to the track array set above
twit.track('foosball');
We that you could update on the fly the track list from the client without needed to detroy the stream :)
Hi ladies, gentlemen
I have a weird problem I can't seem to be able to trace. Any help is appreciated.
This is the error I get:
events.js:50
throw new Error("Uncaught, unspecified 'error' event.");
^
Error: Uncaught, unspecified 'error' event.
at EventEmitter.emit (events.js:50:15)
at ClientRequest. (/root/node/test/node_modules/ntwitter/lib/twitter.js:251:14)
at ClientRequest.emit (events.js:67:17)
at HTTPParser.onIncoming (http.js:1258:11)
at HTTPParser.onHeadersComplete (http.js:102:31)
at CleartextStream.ondata (http.js:1147:24)
at CleartextStream._push (tls.js:367:27)
at SecurePair.cycle (tls.js:688:20)
at EncryptedStream.write (tls.js:122:13)
at Socket.ondata (stream.js:38:26)
It worked on localhost, for a while. On my server it doesn't. At all.
Thanks in advance
Fabian
.updateStatus(myString)
returns a missing parameter error
Hi,
nTwitter gives the following error when I try to connect when behind a proxy.
Error: getaddrinfo ENOENT
How can we set proxy for the communication ?
Hello,
I'm not sure, but has this functionality been stripped?
https://github.com/technoweenie/twitter-node/blob/master/lib/twitter-node/index.js#L196
Because it's actually useful.
Cheers
I ran into this issue today with statuses/mentions and statuses/retweets_of_me:
https://dev.twitter.com/discussions/6664
it's a simple fix, which I did with my local copy of ntwitter, just add a trailing slash like so:
var url = '/statuses/retweets_of_me.json/';
I think there should be special handling for the first message the streaming api sends. When I'm listening to the "data" event I expect only statuses to appear and not the first {friends: ['foo']} object.
It should be really easy to implement looking at https://github.com/AvianFlu/ntwitter/blob/master/lib/twitter.js#L247
Do you agree?
Twitter cannot return more than 500 results in a single call at present, and will pass in a paging URL to get the next set of results. ntwitter needs support to recurse through these and build the whole dataset.
Hi there,
I've got this very simple app :
var twitter = require('ntwitter');
var credentials = require('./credentials.js');
var http = require('http');
var port = process.env.PORT || 5000;
var httpServer = http.createServer(function (request, response) {
request.addListener('end', function () {
clientFiles.serve(request, response);
});
}).listen(port);
var io = require('socket.io').listen(httpServer);
var new_tweet = {};
var t = new twitter({
consumer_key: credentials.consumer_key,
consumer_secret: credentials.consumer_secret,
access_token_key: credentials.access_token_key,
access_token_secret: credentials.access_token_secret
});
io.sockets.on('connection', function (socket) {
t.stream(
'statuses/filter',
{ track: ['awesome', 'cool', 'rad', 'gnarly', 'groovy'] },
function(stream) {
stream.on('data', function(tweet) {
//console.log(tweet.text);
new_tweet = tweet.text;
socket.emit('new_tweet', new_tweet);
});
}
);
});
Well anyone can tried it, quiet simple and straightforward. The thing is that sometime it crashes, and I do not get why ??
The log error is :
11:55:32 web.1 | events.js:68
11:55:32 web.1 | throw new Error("Uncaught, unspecified 'error' event.");
11:55:32 web.1 | ^
11:55:32 web.1 | Error: Uncaught, unspecified 'error' event.
11:55:32 web.1 | at EventEmitter.emit (events.js:68:15)
11:55:32 web.1 | at ClientRequest.Twitter.stream (/usr/local/lib/node_modules/ntwitter/lib/twitter.js:251:14)
11:55:32 web.1 | at ClientRequest.EventEmitter.emit (events.js:88:17)
11:55:32 web.1 | at HTTPParser.parserOnIncomingClient [as onIncoming] (http.js:1455:7)
11:55:32 web.1 | at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:111:23)
11:55:32 web.1 | at CleartextStream.socketOnData [as ondata] (http.js:1366:20)
11:55:32 web.1 | at CleartextStream.CryptoStream._push (tls.js:495:27)
11:55:32 web.1 | at SecurePair.cycle (tls.js:849:20)
11:55:32 web.1 | at EncryptedStream.CryptoStream.write (tls.js:230:13)
11:55:32 web.1 | at Socket.ondata (stream.js:38:26)
11:55:32 web.1 | process terminated
11:55:32 system | sending SIGTERM to all processes
Here is the package.json file for those of you who would like to try :
{
"name": "Twitter.stream.ringthebell.io",
"description": "Twitter server allowing to fetch the twitter stream API and push to a javascript client",
"version": "0.0.1",
"dependencies": {
"socket.io" : "0.9.10",
"ntwitter": "0.4.1"
},
"engines": {
"node": "0.8.x",
"npm": "1.1.49"
}
}
Any help would be much much appreciate :)
Please not that using only console.log and removing the socket.io makes it work perfectly (didn't yet see a crash)
Will support be added for:
twit.stream('statuses/user_timeline'
Need to install [email protected]
for use ntwitter
on Node 0.8.x, but [email protected]
actually depend on [email protected]
.
$ npm ls
/Users/okuryu/work/ura
└─┬ [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
$ grep keygrip node_modules/ntwitter/package.json
"keygrip": "0.1.x"
There's no real way to do this actually, since just numbers is also a valid twitter username: http://twitter.com/1337
Perhaps a change that lets you specify if you're using id's or screen_names?
The other fix, if you still wanted to remain optimistic that most usernames aren't numbers (or don't start with numbers), would be to use a regex to check if it's a line instead of parseInt, because parseInt('20string') == 20.
https://github.com/AvianFlu/ntwitter/blob/master/lib/twitter.js#L582
I've got the following settings:
twitter.stream('statuses/filter', {
track : "pizza",
locations : '-150.75,0, -60,90'
}, function(stream) {
stream.on('data', function (tweet) {
// do stuff
});
});
Is the error between my keyboard and monitor, or is something else going on?
Question related to the API limits, It might something I'm just missing, not sure though:
If I do this:
twit.showUser(ids, function(error, response) {
console.log(response)
}
Where {ids} is an Array, with length < 100, all is well.
When I do the same and IDs is > 100, it fails.
This is based on:
https://dev.twitter.com/docs/api/1.1/get/users/lookup
And specifically:
for up to 100 users per request
Is this somehow managed in ntwitter or do I need to manage this outside? if so, any recommendation on how to manage that?
When I do a stream with follow I get an "Uncaught, unspecified 'error' event." Example:
tweet.stream 'statuses/filter',
track: "test"
follow: "joe"
, (stream) ->
stream.on 'data', (data) ->
client_data = {
content : data.text
img : data.user.profile_image_url_https
user : data.user.screen_name
tags : []
}
Is this not legal? If I just do the track it works great. Locations work too, but not follow.
Line 1144, the function signature for fetch should be:
function fetch(err, data) {
Which adds the "err" parameter.
I can make a pull request if you'd like.
HI, really nice module you guys have here.
Tweeting is nice, but I would like to be able to tweet with media. That'd be sweet. :)
https://dev.twitter.com/docs/api/1/post/statuses/update_with_media
Took me a while to debug this: I was trying to follow (createFriendship
) someone, and the API was responding with a 404. It turns out it's because I was passing an ID as a string -- as recommended by Twitter [1] -- which ntwitter was considering a screenname instead of an ID:
https://github.com/AvianFlu/ntwitter/blob/master/lib/twitter.js#L841-L844
What to do here? In my case, I only have the ID, not the screenname, and it's coming from a string (the cookie from "Sign in with Twitter" functionality). As a temporary workaround, I can parseInt()
on it, but that's obviously not recommended.
Would be nice to support string IDs. What do you think? Thanks! And thanks for the great library and work in general. =)
[1] https://dev.twitter.com/docs/things-every-developer-should-know
I can't figure out how to reply to a certain status. In the API, one of the optional parameters when updating a status is <in_reply_to_status_id>
(I also tried <in_reply_to_status_id_str>
). However, it's not replying to the status, only updating the status with the @username. Has anyone run into this issue too or found a solution?
Allow ntwitter to install via npm under node 0.5.x.
Hi, we hacked ntwitter a while back to set a hard threshold on the number of calls the module would make (so we could guarantee that we would stay within the api rate limit).
I'm too embarrassed by the code, and it was only done for one or two methods, so I want to ask for an opinion on how to do it correctly. What we ended up doing was modifying Twitter.prototype._getUsingCursor
like so:
var use_limit = params.limit || false
if (data.next_cursor_str === '0') {
callback(null, result);
} else if (use_limit && result.length >= use_limit) {
callback(null, result);
} else {
params.cursor = data.next_cursor_str;
self.get(url, params, fetch);
}
and we had to hack the methods we wanted to be able to add a use_limit key to the params:
Twitter.prototype.getFollowersIds = function(id, callback)
else if(typeof id==='object'){
...
params.limit = id.limit;
}
I'd do a pull request but I'm not convinced our code is clean enough and its a bit out dated now (but working fine otherwise)
Currently, when I try to submit a "!" character to updateStatus(message, function (err, data) {
where var message = "Hourly Update!"
, I'm greeted with errors:
data: '{"errors":[{"message":"Could not authenticate you","code":32}]}',
statusCode: 401 }
When I try to start a search stream with track=test,test'ing it fails.
track=test works fine
track=test,test'ing => 401 error
The response I receive is a 401 and I suspect that when POST 'ing the oauth is not done correctly.
Please let me know what extra information I can provide to further debug this issue?
As of Nov 30th I am getting a 406 response on all stream search requests?
Hi,
I am using ntwitter to stream statuses/filter, tracking only one small bounding box.
The stream can run well during days, sometimes weeks, but from time to time the following error starts to get fired almost continuously:
"Easy there, Turbo. Too many requests recently. Enhance your calm."
I get peaks of CPU consumption when this happens, and moreover data is not retrieved from twitter anymore.
This does not happen when a lot of activity is ongoing on twitter. Also, no 'limit' event is ever triggered.
I use immortal-ntwitter (https://github.com/horixon/immortal-ntwitter) to reconnect properly on errors, but when this one happens the only solution I have is to kill the node-js process and restart it (then this error never fires right back).
Does this problem occur to you guys also? Any suggestion on how it could be fixed?
Thanks,
m
I think Twitter Trend API change its endpoint and deprecate old one, getTrends and getCurrentTrends should change to trends/:woeid
to get trends information.
The search example in README.md
fails when you try to run it.
twit.search('nodejs OR #node', function(err, data) {
console.log(data);
});
It should, instead be:
twit.search('nodejs OR #node', {}, function(err, data) {
console.log(data);
});
Twitter.prototype.search
starting on line 155
of twitter.js
will set params
to null
without the empty object, and will then attempt to run that null
through the util.merge
function with the query parameters. This results in the following error:
TypeError: Cannot set property 'q' of null
at Object.merge (/path/to/node_modules/ntwitter/lib/utils.js:9:18)
at Twitter.search (/path/to/node_modules/ntwitter/lib/twitter.js:167:18)
at Object.<anonymous> (/path/to/scratch.js:55:8)
Hi, Sometimes I have the following error: [Error: HTTP Error 401: Unauthorized, API message: {"errors":[{"message":"Could not authenticate you","code":32}]}]
data: '{"errors":[{"message":"Could not authenticate you","code":32}]}',
statusCode: 401 } from time to time (sometimes it works correctly).I use 2 different twitter applications and call updateStatus method turn by turn in both.
I looked at #74, but it doesn't work if I even don't send characters: !'()*.
It has been 5 month since the latest update and the library is not compatible with twitters 1.1 rest api. Plenty of good pull requests.
But nobody is pulling.
So following the history of node-twitter. We are now on the 3 fork of the library.
https://github.com/technoweenie/twitter-node
https://github.com/jdub/node-twitter
https://github.com/AvianFlu/ntwitter
Do we need a 4. fork ?
I think the best option would be to get @AvianFlu to add some collaborator.
I am trying to stream location based twitter streams using ntwitter stream api
. I have run into an issue where following sample code gives me a 404 error.
The stream url formed is: https://stream.twitter.com/1.1//statuses/filter.json
, notice the //
before statuses
.
Twitter says, Unknown URL. See Twitter Streaming API documentation at http://dev.twitter.com/pages/streaming_api
.
When I hard code the url to https://stream.twitter.com/1.1/statuses/filter.json
, removing the extra /
, everything runs fine.
I am not sure if this is really bug, but wanted to bring it your notice.
presumably all tweets that contain apostrophes fail. With the demo code from http://www.catonmat.net/blog/nodejs-modules-ntwitter/ i replace:
.updateStatus('Test tweet from ntwitter/' + twitter.VERSION,
with:
.updateStatus('test \' ',
and then i get:
Tweeting failed: Error: HTTP Error 401: Unauthorized, API message: {"errors":[{"message":"Could not authenticate you","code":32}]}
(note this is not verifyCredentials reporting this error, but updateStatus, and if i tweet without apostrophes, then it works)
I npm-installed ntwitter two days ago, so i'm using version 0.2.8 (on a Debian server).
For now i will avoid using apostrophes in my tweets :)
Sometimes I receive the tweets through the 'error' events emitted by ntwitter's stream object:
stream.on('error', function (err) {
if (err.text !== undefined) {
console.log("twitter error: "+inspect(err)); <-- a full, working tweet is printed here!
}
});
It's a bit random (it can happen or not, even if I don't touch my settings/code/tokens)
my guess it's some kind of http code misinterpreted by ntwitter as "error", but still valid? maybe a "url changed" or "redirection" http code?
I don't have much time right now to dig inside ntwitter internals and figure out what is happening, but if I can get more details I'll post them here.
my config: node 0.6 / ntwitter 0.3.0
When using streaming api with location filter, the first pair must be the SW corner.
I realized that it didn't show up on my console.
I Worked with this library succesfully for a couple of projects. It has a nice API and the most important thing is that it works! I think is time for a restructuration and i want to contribute. We probably need to split the unique twitter.js file into several modules. I want to make a util.js file, divide the REST and streaming API and maybe a search api module. Maybe you want to make some search API calls without an API key.
This is just the beginning of a deep change, and i think it worth it. Would you?
I copied the code for the user streams using "track":
stream.on('data', function (data) {
console.log(console.dir(data));
});
Besides the tweets this code also outputs some "undefined"s on my console.
I'm using node 0.6.6
Edit: I'm sorry for confusing you. The cause is of course that console.dir already outputs to console and returns undefined.
You should remove all occurrences of console.log(console.dir(foo));
with console.dir(foo);
in the example codes.
can't pipe!
I've been testing it locally and on nodejitsu, but after a few hours, the stream seems to stop working. Is this because i'm not handling stream disconnections when a user disconnects by closing their tab/window ?
This is the code i'm using...
twitter
.stream('statuses/filter', {track: 'diablo'}, function(stream) {
stream.on('data', function (data) {
var encoded = strencode(data);
var tweet = JSON.parse(encoded);
var array = {
"id": tweet.id,
"screen_name": tweet.user.screen_name,
"text" : tweet.text,
"profile_image_url" : tweet.user.profile_image_url
};
io.sockets.send(strencode(array));
});
stream.on('end', function (response) {
// Handle a disconnection
});
stream.on('destroy', function (response) {
// Handle a 'silent' disconnection from Twitter, no end/error event fired
});
});
Hi,
When I updated code to v0.5.0 updateStatus function returns :
{"errors":[{"message":"Could not authenticate you","code":32}]}
Reverting back to 0.4 works . I assume it's connected with twitter API 1.1 ?
Had to install [email protected] to get support for the "setSecureCookie" function. Looks like it's just switching a few API calls.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.