GithubHelp home page GithubHelp logo

tuiter's Introduction

Tuiter

Tuiter is a Node.JS library that makes the interaction with the Twitter API easy.

How to install

    npm install tuiter

How to use

Create a Tuiter object with your Twitter application keys

    var keys = {
        "consumer_key" : "blablabla"
      , "consumer_secret" : "blablabla" 
      , "access_token_key" : "blablabla"
      , "access_token_secret" : "blablabla"
    };

    var tu = require('tuiter')(keys);

Use the api methods as you want, for example:

    tu.mentionsTimeline({trim_user: true}, function(err, data){
      console.log(data);	
    });

Using the Streaming is a little different:

    tu.filter({track: ['soccer','pokemon']}, function(stream){
      // tweets :)
      stream.on('tweet', function(data){
        console.log(data);
      });
    });

It is possible to use lat, long objects for describing location bounding boxes:

    tu.filter({locations: [{lat: -90, long: -180}, {lat: 90, long: 180}]}, function(stream){
      // tweets :)
      stream.on('tweet', function(data){
        console.log(data);
      });
    });

Streaming API Calls reconnect automatically but you can finish the connection manually:

    tu.filter({track: "milanesa"}, function(stream){

      setTimeout(function(){      
        stream.emit('end');
      }, 2 * 3 * 4);
    });

API Call responses are Stream objects so you can pipe (for example to a file):

    var output = fs.createWriteStream(__dirname + '/output.txt');

    tuiter.sample(function(stream){
      stream.pipe(output);
    });

Although you can explicitly reconnect using other params

    var st;
    tu.filter({track: "milanesa"}, function(stream){
      stream = st;
    });

    setTimeout(function(){      
      st.emit('reconnect', {track: ["ketchup", "papas fritas"]});
    }, 2 * 3 * 4);

Showcase

You can find Projects and demos using Tuiter here

Features

Available methods

All Search API, REST API V1.1 and Streaming API methods are available. The names of the methods in the library are listed Here

Test

Add your development keys in test/keys.json file like as the follow lines:

    var keys.json = {
        "consumer_key" : "6ffkyGE7aWgHyOXVAlzZA"
      , "consumer_secret" : "UFiyaFW9RPSacY7547jlIvk9E6Jn07StbgrDkdtKV8" 
      , "access_token_key" : "308711490-N62VGRYIvNPgBsqDV0nDW491J9q7GJsXqTHm4JpM"
      , "access_token_secret" : "QVXnxCI7vO3wtkbxBfMfsDZWHCQX23DipMMTObmak"
    };

Download testing modules dependencies

npm install

Run tests

make test

License

(The MIT License)

Copyright (c) 2012 Dan Zajdband <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

tuiter's People

Contributors

goopi avatar impronunciable avatar koenpunt avatar mef avatar retrofox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tuiter's Issues

Cannot manually reconnect stream.

Calling a stream.emit('reconnect', {track: ['new', 'stuff', 'here']}), as it says in the docs, does not reconnect. I only get data for the original filter, and not the new filter.

Unable to connect

Hi, in the last few days I have found out that it doesn't retrieve anything from the streaming api anymore. Could you help me on how to better debug it? Is there something to have a more verbose output on console?

Using:
Node v0.10.26
Npm 1.4.3
on my local machine MacOSX 10.7.4

Maybe reconnection/ratelimit issue

Hi, after I have updated from 0.2.8 to 0.2.10 I noticed that after 6/8 hours it stops crawling for data without any error.

I will leave it active again in 24/7 mode to test it. What do you think about it?
Could it be something about the latest ratelimit/reconnection commits?

'Authentication credentials were missing or incorrect' error

Hi,
I am getting the following error since a couple of hours ago (worked fine before):

{ code: 401,
  definition: 'Unauthorized',
  description: 'Authentication credentials were missing or incorrect.' }

But my keys haven't changed (I renewed the token just in case).
Could something have change in the API or is it some local problem?
Regards

Error: Bad token

Hi,
sometimes I have these errors on the stream and the app stops to retrieve tweets from the streaming API, the process is still running though.

https://gist.github.com/Fabryz/3f244dd3f47a3423ed06

I think that the problem may rely in:

  • some unicode encoded characters
  • the fact that sometimes the JSON is not correctly merged from the chunks arrived on the streaming api. If you see on "gistfile2.txt" the JSON seems broken.

Is there a way to just skip this kind of event and let the stream go on? Without having to use the reconnection

silently fails in case of wrong twitter app tokens

Under some conditions, tuiter will fail to work, without ever notifying of any error.

Steps to reproduce

  1. instantiate Tuiter object with wrong twitter application keys
  2. use a streaming API endpoint

Expected result

An error thrown (e.g. { errors: [ { code: 215, message: 'Bad Authentication data.' } ] } )

Observed result

No error is thrown, the application continues to runm although not ever returning any tweet, obviously.

using DEBUG=tuiter does not notify of an authentication problem either.

workaround is to perform a REST API request, in order to have an error to be thrown...

"Bad Token"

Hello!

I'm using this library, and it worked perfectly.
Actualize the js node version, and started giving me the error http headers, I searched a bit, and I modified the file in socket.io / lib / manager.js.
I did well, but now I get an error like this:

"bad token", there seems to be an error with the Tweets coming because I connected. I always entering stream.on ("error", function (error) {

Thank you!

Raul. -

resume on rate limit crashes

Whenever rate limit gets reached, the tuiter process crashes with the following message:

  debug('rate limit reached, sleeping during', Math.ceil(sleep_duration/60000)
                                                         ^
ReferenceError: sleep_duration is not defined
    at Tuiter.handleRateLimit (/path/node_modules/tuiter/lib/tuiter.js:197:58)

UseTuiter to authorize other users

Hi,
Is it possible to use Tuiter for authorizing other users (as with the "Sign in with Twitter" button)?
If so, where can I find an example how to do it?
Thanks

Unhandled stream error in pipe.

I was testing out Tuiter v0.2.0 and this happens while using the streaming API with certain keywords:

โžœ tweet-a-table git:(master) โœ— node server.js

  • Stream started *

stream.js:81
throw er; // Unhandled stream error in pipe.
^
Error: incorrect header check
at Zlib._binding.onerror (zlib.js:283:17)

Quick test code:
https://gist.github.com/df809d81622aeb5a0b77

Also: sometimes the application just exits instead of giving this error, all I was changing were the keywords for the track API

EDIT: Dang, I see I have it also on v0.1.1 among the "Error: SyntaxError: Unexpected end of input"

memory leak problem

There seems to be a memory leak problem on tuiter's REST API methods.

example code to reproduce the issue:

var cnt = -1;

makeRequest()

function makeRequest() {
// 1. perform a request to the tuiter API
// 2. re-attempt after a short delay
// 3. log rss memory usage every 50 requests
    cnt++

    tu.showUser({screen_name:'jack' }, function(err, data){
        if (err) console.log('error', err, data)
        if (cnt % 50 == 0) {
            // display rss memory usage
            console.log(process.memoryUsage().rss)
        }
        var t = setTimeout(function() {
            // re-run the request after a short delay
                makeRequest()
        }
        , 50)
        t = null
        data = null
        err = null
    })

}

The log will show that the memory usage is constantly increasing. Am I doing something wrong?

Could this be related to ladjs/superagent#152 or to ladjs/superagent#193

Any known workaround or fix ?

crashing when disconnections occur

I am experiencing crashes of my process using REST API, whenever network is disconnected, or when for some reason there is a timeout of twitter's response.

events.js:71
        throw arguments[1]; // Unhandled 'error' event
                       ^
Error: socket hang up
    at createHangUpError (http.js:1264:15)
    at CleartextStream.socketCloseListener (http.js:1315:23)
    at CleartextStream.EventEmitter.emit (events.js:126:20)
    at SecurePair.destroy (tls.js:938:22)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)

Variations of this are ""connect ETIMEDOUT" instead of socket hang up.

Is there any way to catch these errors ?

rest#showUser error

There are two issues with the showerUser api get request:

  1. The version number needs to be specified. In the config.json mapping, it is currently 'version' which doesn't work against the current Twitter API.
    Resolved by setting the version to 1 in config.json
  2. required params are removed via utils#replaceURL.
    Resolved by commenting out the method preprocessing in rest.js.

Something broke on v0.1.2

Sorry for the generic title, but I just re-deployed my app and had some errors on Twitter Streaming API.

Will investigate if it's really my code or some errors not managed on Tuiter, I post here as a reminder to myself

Issue with integer length for tweet id

user tuiter#filter...

a tweet has issues with with the integer value for the id

Example:
Actual Tweet's Id: 267081518403440641,
Value of data.id: 267081518403440640
Value of data.id_str: '267081518403440641'

Haven't dug deeper but perhaps need to use one of the big integer libraries. ECMAScript numbers are represented in binary as IEEE-754 (IEC 559) Doubles, with a resolution of 53 bits, giving an accuracy of 15-16 decimal digits

Rate limiting

Any way to understand if i'm being blocked by the twitter rate-limit or something?

I'm investigating why after some time the stream suddently stops

API Lazy load

API's should load when necesary. Need to avoid the load of innecesary API'S (i.e: If I'm using only Streaming API, don't load the full REST API methods.)

cannot end stream

Hi,

Using Tuiter 0.2.6, I cannot manually disconnect a stream, using the code from README.js.

Looks like stream.emit('end'); has no effect.

Am I missing something ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.