Git Product home page Git Product logo

twit's Introduction

twit

Twitter API Client for node

Supports both the REST and Streaming API.

Installing

npm install twit

Usage:

var Twit = require('twit')

var T = new Twit({
  consumer_key:         '...',
  consumer_secret:      '...',
  access_token:         '...',
  access_token_secret:  '...',
  timeout_ms:           60*1000,  // optional HTTP request timeout to apply to all requests.
  strictSSL:            true,     // optional - requires SSL certificates to be valid.
})

//
//  tweet 'hello world!'
//
T.post('statuses/update', { status: 'hello world!' }, function(err, data, response) {
  console.log(data)
})

//
//  search twitter for all tweets containing the word 'banana' since July 11, 2011
//
T.get('search/tweets', { q: 'banana since:2011-07-11', count: 100 }, function(err, data, response) {
  console.log(data)
})

//
//  get the list of user id's that follow @tolga_tezel
//
T.get('followers/ids', { screen_name: 'tolga_tezel' },  function (err, data, response) {
  console.log(data)
})

//
// Twit has promise support; you can use the callback API,
// promise API, or both at the same time.
//
T.get('account/verify_credentials', { skip_status: true })
  .catch(function (err) {
    console.log('caught error', err.stack)
  })
  .then(function (result) {
    // `result` is an Object with keys "data" and "resp".
    // `data` and `resp` are the same objects as the ones passed
    // to the callback.
    // See https://github.com/ttezel/twit#tgetpath-params-callback
    // for details.

    console.log('data', result.data);
  })

//
//  retweet a tweet with id '343360866131001345'
//
T.post('statuses/retweet/:id', { id: '343360866131001345' }, function (err, data, response) {
  console.log(data)
})

//
//  destroy a tweet with id '343360866131001345'
//
T.post('statuses/destroy/:id', { id: '343360866131001345' }, function (err, data, response) {
  console.log(data)
})

//
// get `funny` twitter users
//
T.get('users/suggestions/:slug', { slug: 'funny' }, function (err, data, response) {
  console.log(data)
})

//
// post a tweet with media
//
var b64content = fs.readFileSync('/path/to/img', { encoding: 'base64' })

// first we must post the media to Twitter
T.post('media/upload', { media_data: b64content }, function (err, data, response) {
  // now we can assign alt text to the media, for use by screen readers and
  // other text-based presentations and interpreters
  var mediaIdStr = data.media_id_string
  var altText = "Small flowers in a planter on a sunny balcony, blossoming."
  var meta_params = { media_id: mediaIdStr, alt_text: { text: altText } }

  T.post('media/metadata/create', meta_params, function (err, data, response) {
    if (!err) {
      // now we can reference the media and post a tweet (media will attach to the tweet)
      var params = { status: 'loving life #nofilter', media_ids: [mediaIdStr] }

      T.post('statuses/update', params, function (err, data, response) {
        console.log(data)
      })
    }
  })
})

//
// post media via the chunked media upload API.
// You can then use POST statuses/update to post a tweet with the media attached as in the example above using `media_id_string`.
// Note: You can also do this yourself manually using T.post() calls if you want more fine-grained
// control over the streaming. Example: https://github.com/ttezel/twit/blob/master/tests/rest_chunked_upload.js#L20
//
var filePath = '/absolute/path/to/file.mp4'
T.postMediaChunked({ file_path: filePath }, function (err, data, response) {
  console.log(data)
})

//
//  stream a sample of public statuses
//
var stream = T.stream('statuses/sample')

stream.on('tweet', function (tweet) {
  console.log(tweet)
})

//
//  filter the twitter public stream by the word 'mango'.
//
var stream = T.stream('statuses/filter', { track: 'mango' })

stream.on('tweet', function (tweet) {
  console.log(tweet)
})

//
// filter the public stream by the latitude/longitude bounded box of San Francisco
//
var sanFrancisco = [ '-122.75', '36.8', '-121.75', '37.8' ]

var stream = T.stream('statuses/filter', { locations: sanFrancisco })

stream.on('tweet', function (tweet) {
  console.log(tweet)
})

//
// filter the public stream by english tweets containing `#apple`
//
var stream = T.stream('statuses/filter', { track: '#apple', language: 'en' })

stream.on('tweet', function (tweet) {
  console.log(tweet)
})

twit API:

var T = new Twit(config)

Create a Twit instance that can be used to make requests to Twitter's APIs.

If authenticating with user context, config should be an object of the form:

{
    consumer_key:         '...'
  , consumer_secret:      '...'
  , access_token:         '...'
  , access_token_secret:  '...'
}

If authenticating with application context, config should be an object of the form:

{
    consumer_key:         '...'
  , consumer_secret:      '...'
  , app_only_auth:        true
}

Note that Application-only auth will not allow you to perform requests to API endpoints requiring a user context, such as posting tweets. However, the endpoints available can have a higher rate limit.

T.get(path, [params], callback)

GET any of the REST API endpoints.

path

The endpoint to hit. When specifying path values, omit the '.json' at the end (i.e. use 'search/tweets' instead of 'search/tweets.json').

params

(Optional) parameters for the request.

callback

function (err, data, response)

  • data is the parsed data received from Twitter.
  • response is the [http.IncomingMessage](http://nodejs.org/api/http.html# http_http_incomingmessage) received from Twitter.

T.post(path, [params], callback)

POST any of the REST API endpoints. Same usage as T.get().

T.postMediaChunked(params, callback)

Helper function to post media via the POST media/upload (chunked) API. params is an object containing a file_path key. file_path is the absolute path to the file you want to upload.

var filePath = '/absolute/path/to/file.mp4'
T.postMediaChunked({ file_path: filePath }, function (err, data, response) {
  console.log(data)
})

You can also use the POST media/upload API via T.post() calls if you want more fine-grained control over the streaming; [see here for an example](https://github.com/ttezel/twit/blob/master/tests/rest_chunked_upload.js# L20).

T.getAuth()

Get the client's authentication tokens.

T.setAuth(tokens)

Update the client's authentication tokens.

T.stream(path, [params])

Use this with the Streaming API.

path

Streaming endpoint to hit. One of:

  • 'statuses/filter'
  • 'statuses/sample'
  • 'statuses/firehose'
  • 'user'
  • 'site'

For a description of each Streaming endpoint, see the Twitter API docs.

params

(Optional) parameters for the request. Any Arrays passed in params get converted to comma-separated strings, allowing you to do requests like:

//
// I only want to see tweets about my favorite fruits
//

// same result as doing { track: 'bananas,oranges,strawberries' }
var stream = T.stream('statuses/filter', { track: ['bananas', 'oranges', 'strawberries'] })

stream.on('tweet', function (tweet) {
  //...
})

Using the Streaming API

T.stream(path, [params]) keeps the connection alive, and returns an EventEmitter.

The following events are emitted:

event: 'message'

Emitted each time an object is received in the stream. This is a catch-all event that can be used to process any data received in the stream, rather than using the more specific events documented below. New in version 2.1.0.

stream.on('message', function (msg) {
  //...
})

event: 'tweet'

Emitted each time a status (tweet) comes into the stream.

stream.on('tweet', function (tweet) {
  //...
})

event: 'delete'

Emitted each time a status (tweet) deletion message comes into the stream.

stream.on('delete', function (deleteMessage) {
  //...
})

event: 'limit'

Emitted each time a limitation message comes into the stream.

stream.on('limit', function (limitMessage) {
  //...
})

event: 'scrub_geo'

Emitted each time a location deletion message comes into the stream.

stream.on('scrub_geo', function (scrubGeoMessage) {
  //...
})

event: 'disconnect'

Emitted when a disconnect message comes from Twitter. This occurs if you have multiple streams connected to Twitter's API. Upon receiving a disconnect message from Twitter, Twit will close the connection and emit this event with the message details received from twitter.

stream.on('disconnect', function (disconnectMessage) {
  //...
})

event: 'connect'

Emitted when a connection attempt is made to Twitter. The http request object is emitted.

stream.on('connect', function (request) {
  //...
})

event: 'connected'

Emitted when the response is received from Twitter. The http response object is emitted.

stream.on('connected', function (response) {
  //...
})

event: 'reconnect'

Emitted when a reconnection attempt to Twitter is scheduled. If Twitter is having problems or we get rate limited, we schedule a reconnect according to Twitter's reconnection guidelines. The last http request and response objects are emitted, along with the time (in milliseconds) left before the reconnect occurs.

stream.on('reconnect', function (request, response, connectInterval) {
  //...
})

event: 'warning'

This message is appropriate for clients using high-bandwidth connections, like the firehose. If your connection is falling behind, Twitter will queue messages for you, until your queue fills up, at which point they will disconnect you.

stream.on('warning', function (warning) {
  //...
})

event: 'status_withheld'

Emitted when Twitter sends back a status_withheld message in the stream. This means that a tweet was withheld in certain countries.

stream.on('status_withheld', function (withheldMsg) {
  //...
})

event: 'user_withheld'

Emitted when Twitter sends back a user_withheld message in the stream. This means that a Twitter user was withheld in certain countries.

stream.on('user_withheld', function (withheldMsg) {
  //...
})

event: 'friends'

Emitted when Twitter sends the ["friends" preamble](https://dev.twitter.com/streaming/overview/messages-types# user_stream_messsages) when connecting to a user stream. This message contains a list of the user's friends, represented as an array of user ids. If the stringify_friend_ids parameter is set, the friends list preamble will be returned as Strings (instead of Numbers).

var stream = T.stream('user', { stringify_friend_ids: true })
stream.on('friends', function (friendsMsg) {
  //...
})

event: 'direct_message'

Emitted when a direct message is sent to the user. Unfortunately, Twitter has not documented this event for user streams.

stream.on('direct_message', function (directMsg) {
  //...
})

event: 'user_event'

Emitted when Twitter sends back a User stream event. See the Twitter docs for more information on each event's structure.

stream.on('user_event', function (eventMsg) {
  //...
})

In addition, the following user stream events are provided for you to listen on:

  • blocked
  • unblocked
  • favorite
  • unfavorite
  • follow
  • unfollow
  • mute
  • unmute
  • user_update
  • list_created
  • list_destroyed
  • list_updated
  • list_member_added
  • list_member_removed
  • list_user_subscribed
  • list_user_unsubscribed
  • quoted_tweet
  • retweeted_retweet
  • favorited_retweet
  • unknown_user_event (for an event that doesn't match any of the above)

Example:

stream.on('favorite', function (event) {
  //...
})

event: 'error'

Emitted when an API request or response error occurs. An Error object is emitted, with properties:

{
  message:      '...',  // error message
  statusCode:   '...',  // statusCode from Twitter
  code:         '...',  // error code from Twitter
  twitterReply: '...',  // raw response data from Twitter
  allErrors:    '...'   // array of errors returned from Twitter
}

stream.stop()

Call this function on the stream to stop streaming (closes the connection with Twitter).

stream.start()

Call this function to restart the stream after you called .stop() on it. Note: there is no need to call .start() to begin streaming. Twit.stream calls .start() for you.


What do I have access to?

Anything in the Twitter API:


Go here to create an app and get OAuth credentials (if you haven't already): https://apps.twitter.com/app/new

Advanced

You may specify an array of trusted certificate fingerprints if you want to only trust a specific set of certificates. When an HTTP response is received, it is verified that the certificate was signed, and the peer certificate's fingerprint must be one of the values you specified. By default, the node.js trusted "root" CAs will be used.

eg.

var twit = new Twit({
  consumer_key:         '...',
  consumer_secret:      '...',
  access_token:         '...',
  access_token_secret:  '...',
  trusted_cert_fingerprints: [
    '66:EA:47:62:D9:B1:4F:1A:AE:89:5F:68:BA:6B:8E:BB:F8:1D:BF:8E',
  ]
})

Contributing

  • Make your changes
  • Make sure your code matches the style of the code around it
  • Add tests that cover your feature/bugfix
  • Run tests
  • Submit a pull request

How do I run the tests?

Create two files: config1.js and config2.js at the root of the twit folder. They should contain two different sets of oauth credentials for twit to use (two accounts are needed for testing interactions). They should both look something like this:

module.exports = {
    consumer_key: '...'
  , consumer_secret: '...'
  , access_token: '...'
  , access_token_secret: '...'
}

Then run the tests:

npm test

You can also run the example:

node examples/rtd2.js

iRTD2

The example is a twitter bot named RTD2 written using twit. RTD2 tweets about github and curates its social graph.


FAQ


License

(The MIT License)

Copyright (c) by Tolga Tezel [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.

Changelog

2.2.11

  • Fix media_category used for media uploads (thanks @BooDoo)

2.2.10

  • Update maximum Tweet characters to 280 (thanks @maziyarpanahi)
  • For streaming requests, use request body for sending params (thanks @raine)
  • Fix getBearerToken endpoint (thanks @williamcoates)
  • Shared Parameter Feature For Media Upload (thanks @haroonabbasi)
  • Don't include params in path for jsonpayload paths (thanks @egtoney)
  • Add support for strictSSL request option (thanks @zdoc01)

2.2.9

  • Use JSON payload in request body for new DM endpoints.

2.2.8

  • Add support for HTTP DELETE; you can now T.delete(...).

2.2.7

  • Don't attempt to reconnect to Twitter API when receiving HTTP status code 413 - request entity too large.

2.2.6

  • Fix zlib error when streaming

2.2.4

  • Fix 401 Unauthorized error on streaming connection reconnect after not being connected for some time (eg. due to > 1min loss of network).

2.2.2

  • Emit parser-error instead of error event if Twitter sends back an uncompressed HTTP response body.

2.2.1

  • Add promise support to Twit REST API calls.

2.2.0

  • Allow omission of new keyword; var t = Twit(config) works, and var t = new Twit(config) works too.
  • Allow setting an array of trusted certificate fingerprints via config.trusted_cert_fingerprints.
  • Automatically adjust timestamp for OAuth'ed HTTP requests by recording the timestamp from Twitter HTTP responses, computing our local time offset, and applying the offset in the next HTTP request to Twitter.

2.1.7

  • Add mime as a dependency.

2.1.6

  • Emit friends event for friends_str message received when a user stream is requested with stringify_friend_ids=true.
  • Handle receiving "Exceeded connection limit for user" message from Twitter while streaming. Emit error event for this case.
  • Emit retweeted_retweet and favorited_retweet user events.
  • Add MIT license to package.json (about time!)

2.1.5

  • Support config-based request timeout.

2.1.4

  • Support POST media/upload (chunked) and add T.postMediaChunked() to make it easy.

2.1.3

  • Fix bug in constructing HTTP requests for account/update_profile_image and account/update_profile_background_image paths.

2.1.2

  • Enable gzip on network traffic
  • Add quoted_tweet event

2.1.1

  • Strict-mode fixes (Twit can now be run with strict mode)
  • Fix handling of disconect message from Twitter
  • If Twitter returns a non-JSON-parseable fragment during streaming, emit 'parser-error' instead of 'error' (to discard fragments like "Internal Server Error")

2.1.0

  • Add message event.

2.0.0

  • Implement Application-only auth
  • Remove oauth module as a dependency

1.1.20

  • Implement support for POST /media/upload
  • Reconnect logic fix for streaming; add stall abort/reconnect timeout on first connection attempt.

1.1.14

  • Emit connected event upon receiving the response from twitter

1.0.0

  • now to stop and start the stream, use stream.stop() and stream.start() instead of emitting the start and stop events
  • If twitter sends a disconnect message, closes the stream and emits disconnect with the disconnect message received from twitter

0.2.0

  • Updated twit for usage with v1.1 of the Twitter API.

0.1.5

  • BREAKING CHANGE to twit.stream(). Does not take a callback anymore. It returns immediately with the EventEmitter that you can listen on. The Usage section in the Readme.md has been updated. Read it.

0.1.4

  • twit.stream() has signature function (path, params, callback)

twit's People

Contributors

alexwhitman avatar amandeepmittal avatar angelxmoreno avatar azat-io avatar boodoo avatar chandler avatar conradoplg avatar egtoney avatar freethejazz avatar haroonabbasi avatar justinmichaelvieira avatar katanacrimson avatar lpinca avatar mahnunchik avatar matomesc avatar matteoagosti avatar maziyarpanahi avatar naramsim avatar ohcrider avatar pdehaan avatar raine avatar rhysd avatar siyfion avatar stefanbohacek avatar the-bobo avatar tigerpfleger avatar ttezel avatar vnglst avatar volox avatar williamcoates 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  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

twit's Issues

stream: add event "friends"

On initial connect, I'm seeing a "tweet" event being dispatched with just a "friends" property (array) - perhaps this should be added into this bit as a new event, considering it's not a "real" tweet?

(Note: I'm using this as t.stream's second arg: { with: 'followings', replies:'all' })

twit stream() API, It's not working on RHEL 5.3, but it's working on Windows Platform very well.

Hi,

The following is my testing sample code:

var stream2 = T.stream('user');

stream2.on('tweet', function (tweet) {

console.log('tweet='+util.inspect(tweet, null, null));

});

stream2.on('connect', function (request) {

//console.log('connect='+util.inspect(request, null, null));
console.log('connect');

});

stream2.on('reconnect', function (request, response, connectInterval) {

console.log('reconnect');

});

stream2.on('disconnect', function (disconnectMessage) {

console.log('disconnect='+util.inspect(disconnectMessage, null, null));

});


It's not working on RHEL 5.3 server.
Test Result is the below.
connect
connect
reconnect
connect
reconnect
connect
reconnect
connect
reconnect
connect
reconnect
connect

It's working on Windows Platform very well.
Test Result is the below.
connect
tweet={ friends: [ 6949902, 215198915 ] }

Please check it out.

Thank you for your help.

Regards,
Thomas Lee

Not tweeting?

So, following your basic example, I worked this code into an app I've written:

//Twitter
global.mTwitOn                  = true; //Whether or not twitter functions are enabled
global.mTwitTimeout             = 20;       //How often [in minutes] the bot can tweet
global.mTwitKey                 = "xx";     //Consumer Key for Twitter
global.mTwitSecret              = "xx";     //Consumer Secret for Twitter
global.mTwitToken               = "xx-xx";      //Access Token for Twitter
global.mTwitTokenSecret         = "xx";     //Access Secret for Twitter

if (mTwitOn) global.mTwit = require("twit");

if (mTwitKey) {
    Log("Connecting to Twitter");
    global.mTwitter = new mTwit({
        consumer_key:         mTwitKey
      , consumer_secret:      mTwitSecret
      , access_token:         mTwitToken
      , access_token_secret:  mTwitTokenSecret
    });
    global.mLastTweeted = null;
    Log("Done");
}

And this is the function to tweet:

callback: function (pUser, pText) {
        if (!mTwitOn) return;
        var sAge = Date.now() - mLastTweeted;
        var sAge_Minutes = sAge / 60000; 
        if(sAge_Minutes < mTwitTimeout) return Speak(pUser, mTweetSpam, SpeakingLevel.Misc, [['{twitime}', mTwitTimeout]], true);
        if (!pText) {
            if (!mCurrentDJ) return;
            mTwitter.post('statuses/update', {
             status: 'Hello World' 
            }, function(err, reply) {});
            mLastTweeted = Date.now();
            return Speak(pUser, mConfirmTweet, SpeakingLevel.Misc);
        }

Those are all spaced out, I'm only posting the relevant code
All of my code works [my Speak function and whatnot, and I'm not getting any errors, but I'm checking the twitter account I'm connected to, and I'm not getting any tweets showing up.

Stream with a lang filter

I know that there is an attribute lang in the Twitter API (user,lang). Would it be possible to stream the api on hashtags and lang ? By passing another arrays of params maybe ?

Follow commas

How do you get the comma separated list for following people to work? The commas seem to get escaped and twitter does not recognize the individual user ids. Also, I see you use GET for the streaming api would it not be better to use POST as 5000 follow ids could become a problem in the URL.

https://dev.twitter.com/docs/api/1/post/statuses/filter

errors parsing twitter response - twit dispatching non-tweet user stream events as tweets

error parsing twitter response. not sure why, guessing it's because of the \r\n contained in the bio? can't really tell. jsonlint doesn't see anything wrong with it either...

This is grabbed out of stderr as well, if that helps.

Error: Error parsing twitter reply: `{"event":"follow","created_at":"Sun Feb 10 03:17:00 +0000 2013","target":{"id":561658570,"default_profile_image":false,"profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/619085747\/2x47kys21qzszs8fg9ko.jpeg","friends_count":28,"favourites_count":4,"profile_link_color":"009999","profile_background_image_url_https":"https:\/\/twimg0-.akamaihd.net\/profile_background_images\/619085747\/2x47kys21qzszs8fg9ko.jpeg","utc_offset":-21600,"screen_name":"Meido_chu","is_translator":false,"followers_count":108,"name":"Media","lang":"en","profile_use_background_image":true,"created_at":"Tue Apr 24 02:25:12 +0000 2012","profile_text_color":"333333","notifications":false,"protected":false,"id_str":"561658570","statuses_count":1374,"url":null,"contributors_enabled":false,"default_profile":false,"profile_sidebar_border_color":"EEEEEE","time_zone":"Central Time (US & Canada)","geo_enabled":false,"verified":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/2949476469\/8e1d977154551ecdba72c713f18b7ad3_normal.jpeg","following":true,"profile_image_url_https":"https:\/\/twimg0-.akamaihd.net\/profile_images\/2949476469\/8e1d977154551ecdba72c713f18b7ad3_normal.jpeg","profile_background_tile":true,"listed_count":2,"profile_sidebar_fill_color":"EFEFEF","location":"In jail","follow_request_sent":false,"description":"Jailed account of @MilitarMaid","profile_background_color":"131516"},"source":{"id":517142024,"default_profile_image":true,"profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme14\/bg.gif","friends_count":8,"favourites_count":63,"profile_link_color":"009999","profile_background_image_url_https":"https:\/\/twimg0-.akamaihd.net\/images\/themes\/theme14\/bg.gif","utc_offset":-21600,"screen_name":"_lithion","is_translator":false,"followers_count":21,"name":"Katy","lang":"en","profile_use_background_image":false,"created_at":"Wed Mar 07 02:49:36 +0000 2012","profile_text_color":"333333","notifications":false,"protected":true,"id_str":"517142024","statuses_count":9517,"url":null,"contributors_enabled":false,"default_profile":false,"profile_sidebar_border_color":"FFFFFF","time_zone":"Central Time (US & Canada)","geo_enabled":false,"verified":false,"profile_image_url":"http:\/\/a0.twimg.com\/sticky\/default_profile_images\/default_profile_0_normal.png","following":false,"profile_image_url_https":"https:\/\/twimg0-.akamaihd.net\/sticky\/default_profile_images\/default_profile_0_normal.png","profile_background_tile":true,"listed_count":0,"profile_sidebar_fill_color":"DDEEF6","profile_banner_url":"https:\/\/twimg0-.akamaihd.net\/profile_banners\/517142024\/1357962753","location":null,"follow_request_sent":false,"description":"They say that even starlight takes time to travel to and fro.\r\n\r\nDon't rely on another's twilight; find your own way forward. \r\n\r\nShine...shine...SHINE!","profile_background_color":"9B1414"}}`

[Streaming Api] Cannot search by bounding box AND keyword.

If I had "track" to my stream that is currently returning only San Francisco tweets, it starts returning me tons of tweets without geo-data.

Maybe this is intentional, but it's not in the documentation, which implies you can do "track" and "language" filters... so I'm led to believe I should be able to do "track" and "locations" right?

Thanks in advance!

Stream authenticating, Post not.

I'm probably doing something stupid, but, I'm able to use the streaming API just fine, but when I try to make a post, the err is:

err:
{ statusCode: 401,
data: '{"error":"Could not authenticate with OAuth.","request":"/1/statuses/update.json?status=Test"}',

Here's the code I'm trying:
T.post('statuses/update', { status: 'Test' }, function(err, reply) {
console.log(err);
});

Can I not be currently streaming with my auth and also make posts at the same time possibly?

stall warnings

er.com/docs/streaming-apis/parameters

Where can I hook this event?

Stream disconnect event not firing.

I have a lightweight little bot running and heavily relying on the Stream API. I notice that once a day my bot disconnects with the following message:

events.js:48
        throw arguments[1]; // Unhandled 'error' event
                       ^
Error: Connection lost: The server closed the connection.
    at Protocol.end (/var/www/vhosts/iweigh.net/bot/node_modules/mysql/lib/protocol/Protocol.js:73:13)
    at Socket.onend (stream.js:80:10)
    at Socket.emit (events.js:88:20)
    at TCP.onread (net.js:388:51)

Here's the code I'm using. From the README, this should be catching the disconnect from Twitter and gracefully exiting (and at least logging my Stream Disconnection message).

stream.on('disconnect', function(data) {
        console.log(data);
        console.log('[TWITTER] Stream disconnection!');
});

Any thoughts?

Two Issues

First of all examples are not working, randomly they are returning 404 for few situations

second 5 tests were failing on my machine. Don't know y though, following is the output.

✖ 5 of 43 tests failed:

  1. REST API GET statuses/home_timeline:
    AssertionError: "undefined" == true
    at checkTweet (/Users/mohitthakral/Projects/twitterbot/node_modules/twit/tests/rest.js:439:10)
    at /Users/mohitthakral/Projects/twitterbot/node_modules/twit/tests/rest.js:126:7
    at handler (/Users/mohitthakral/Projects/twitterbot/node_modules/twit/lib/oarequest.js:278:12)
    at passBackControl (/Users/mohitthakral/Projects/twitterbot/node_modules/twit/node_modules/oauth/lib/oauth.js:367:11)
    at IncomingMessage. (/Users/mohitthakral/Projects/twitterbot/node_modules/twit/node_modules/oauth/lib/oauth.js:386:9)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:920:16
    at process._tickCallback (node.js:415:13)

  2. REST API GET statuses/mentions_timeline:
    AssertionError: "undefined" == true
    at checkTweet (/Users/mohitthakral/Projects/twitterbot/node_modules/twit/tests/rest.js:439:10)
    at /Users/mohitthakral/Projects/twitterbot/node_modules/twit/tests/rest.js:137:7
    at handler (/Users/mohitthakral/Projects/twitterbot/node_modules/twit/lib/oarequest.js:278:12)
    at passBackControl (/Users/mohitthakral/Projects/twitterbot/node_modules/twit/node_modules/oauth/lib/oauth.js:367:11)
    at IncomingMessage. (/Users/mohitthakral/Projects/twitterbot/node_modules/twit/node_modules/oauth/lib/oauth.js:386:9)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:920:16
    at process._tickCallback (node.js:415:13)

  3. REST API GET direct_messages:
    AssertionError: "undefined" == true
    at Object.checkDm (/Users/mohitthakral/Projects/twitterbot/node_modules/twit/tests/rest.js:454:10)
    at /Users/mohitthakral/Projects/twitterbot/node_modules/twit/tests/rest.js:234:15
    at handler (/Users/mohitthakral/Projects/twitterbot/node_modules/twit/lib/oarequest.js:278:12)
    at passBackControl (/Users/mohitthakral/Projects/twitterbot/node_modules/twit/node_modules/oauth/lib/oauth.js:367:11)
    at IncomingMessage. (/Users/mohitthakral/Projects/twitterbot/node_modules/twit/node_modules/oauth/lib/oauth.js:386:9)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:920:16
    at process._tickCallback (node.js:415:13)

  4. streaming API events direct_message event:
    Error: timeout of 30000ms exceeded
    at null. (/Users/mohitthakral/Projects/twitterbot/node_modules/twit/node_modules/mocha/lib/runnable.js:167:14)
    at Timer.listOnTimeout as ontimeout

  5. user events friends:
    AssertionError: "undefined" == true
    at checkFriendsMsg (/Users/mohitthakral/Projects/twitterbot/node_modules/twit/tests/user-stream.js:12:5)
    at OARequest. (/Users/mohitthakral/Projects/twitterbot/node_modules/twit/tests/user-stream.js:25:13)
    at OARequest.EventEmitter.emit (events.js:95:17)
    at null. (/Users/mohitthakral/Projects/twitterbot/node_modules/twit/lib/oarequest.js:58:42)
    at EventEmitter.emit (events.js:95:17)
    at Parser.parse (/Users/mohitthakral/Projects/twitterbot/node_modules/twit/lib/parser.js:41:16)
    at IncomingMessage. (/Users/mohitthakral/Projects/twitterbot/node_modules/twit/lib/oarequest.js:138:21)
    at IncomingMessage.EventEmitter.emit (events.js:95:17)
    at IncomingMessage. (stream_readable.js:746:14)
    at IncomingMessage.EventEmitter.emit (events.js:92:17)
    at emitReadable
    (_stream_readable.js:408:10)
    at emitReadable (_stream_readable.js:404:5)
    at readableAddChunk (_stream_readable.js:165:9)
    at IncomingMessage.Readable.push (_stream_readable.js:127:10)
    at HTTPParser.parserOnBody as onBody
    at CleartextStream.socketOnData as ondata
    at CleartextStream.read as _read
    at CleartextStream.Readable.read (_stream_readable.js:320:10)
    at EncryptedStream.write as _write
    at doWrite (_stream_writable.js:221:10)
    at writeOrBuffer (_stream_writable.js:211:5)
    at EncryptedStream.Writable.write (_stream_writable.js:180:11)
    at write (_stream_readable.js:583:24)
    at flow (_stream_readable.js:592:7)
    at Socket.pipeOnReadable (stream_readable.js:624:5)
    at Socket.EventEmitter.emit (events.js:92:17)
    at emitReadable
    (_stream_readable.js:408:10)
    at emitReadable (_stream_readable.js:404:5)
    at readableAddChunk (_stream_readable.js:165:9)
    at Socket.Readable.push (_stream_readable.js:127:10)
    at TCP.onread (net.js:526:21)

npm ERR! weird error 5
npm ERR! not ok code 0

OARequest.prototype.end - Potentially misleading exception message.

Was thinking that the error message shown here is potentially misleading when its the callback that caused the exception, and in such situations losing the original exception could be a problem when your debugging:

'''
try {
var parsed = JSON.parse(raw);
return callback(null, parsed);
} catch(e) {
var error = new Error('twitter reply is not a valid JSON string.');
error.twitterReply = raw;
return callback(error, null);
}
'''

Cache

Since Twitter limits request at 350 reqs/h, is there a way to cache request for a couple of hours or something?

Error: Error parsing twitter reply

Parser crashed on this tweet JSON:

{"created_at":"Sun Dec 16 09:57:16 +0000 2012","id":280250229876486144,"id_str":"280250229876486144","text":"\u041a\u043e\u0442 \u0438 \u043b\u0435\u043d\u0438\u0432\u0438\u0446\u0430 @ \u043f\u0440\u0438\u043d\u0446\u0435\u0441\u044c\u044f \u043d\u043e\u0440\u0430 http://t.co/tdX0aNSq","source":"\u003ca href="http://instagr.am" rel="nofollow"\u003eInstagram\u003c/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":209665061,"id_str":"209665061","name":"\u0425\u0430\u0448\u0438\u043c\u043e\u0432\u0430 \u0415\u0432\u0433\u0435\u043d\u0438\u044f","screen_name":"Ohh_jane","location":"","url":"http://www.formspring.me/SuperZhenya","description":"\u0442\u044b \u0432\u043e\u043e\u0431\u0449\u0435 \u043e \u0447\u0435\u043c?","protected":false,"followers_count":58,"friends_count":36,"listed_count":0,"created_at":"Fri Oct 29 17:05:30 +0000 2010","favourites_count":217,"utc_offset":25200,"time_zone":"Novosibirsk","geo_enabled":true,"verified":false,"statuses_count":2028,"lang":"ru","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http://a0.twimg.com/profile_background_images/673275719/29a8bb4a29f5fc308bee9aeac18fc1d7.jpeg","profile_background_image_url_https":"https://si0.twimg.com/profile_background_images/673275719/29a8bb4a29f5fc308bee9aeac18fc1d7.jpeg","profile_background_tile":true,"profile_image_url":"http://a0.twimg.com/profile_images/2665901791/791b0a9e7936add9b00ddc1f3fcbb1cb_normal.jpeg","profile_image_url_https":"https://si0.twimg.com/profile_images/2665901791/791b0a9e7936add9b00ddc1f3fcbb1cb_normal.jpeg","profile_banner_url":"https://si0.twimg.com/profile_banners/209665061/1349017512","profile_link_color":"0084B4","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":{"type":"Point","coordinates":[54.99534607,82.89186096]},"coordinates":{"type":"Point","coordinates":[82.89186096,54.99534607]},"place":{"id":"679cf8e8e64889c3","url":"http://api.twitter.com/1/geo/id/679cf8e8e64889c3.json","place_type":"city","name":"\u041d\u043e\u0432\u043e\u0441\u0438\u0431\u0438\u0440\u0441\u043a","full_name":"\u041d\u043e\u0432\u043e\u0441\u0438\u0431\u0438\u0440\u0441\u043a, \u041d\u043e\u0432\u043e\u0441\u0438\u0431\u0438\u0440\u0441\u043a","country_code":"RU","country":"\u0420\u043e\u0441\u0441\u0438\u044f","bounding_box":{"type":"Polygon","coordinates":[[[82.750613,54.803186],[82.750613,55.199782],[83.160763,55.199782],[83.160763,54.803186]]]},"attributes":{}},"contributors":null,"retweet_count":0,"entities":{"hashtags":[],"urls":[{"url":"http://t.co/tdX0aNSq","expanded_url":"http://instagr.am/p/TSwvNVmeuk/","display_url":"instagr.am/p/TSwvNVmeuk/","indices":[32,52]}],"user_mentions":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"ru"}

http://jsonlint.com/ said it is valid JSON

npm ls shows bundled oauth dep as "extraneous"

Perhaps this should be listed both under bundledDependencies and dependencies?

katana@serenity ~/repos/twit/
$ npm ls
[email protected] /home/katana/repos/twit
├── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └─┬ [email protected]
│   ├── [email protected]
│   └─┬ [email protected]
│     └─┬ [email protected]
│       ├─┬ [email protected]
│       │ ├── [email protected]
│       │ └─┬ [email protected]
│       │   └── [email protected]
│       └── [email protected]
└── [email protected] extraneous

npm ERR! extraneous: [email protected] /home/katana/repos/twit/node_modules/oauth
npm ERR! not ok code 0

favorites/create gives "statusCode 401" and "code 32"

I get "Could not authenticate you" error when trying to post a fav, I reviewed if the code and access tokens, they are working doing a post "statuses/update" successfully, but with the fav I wasn't lucky.

  {
      "statusCode": 401,
      "data": "{\"errors\":[{\"message\":\"Could not authenticate you\",\"code\":32}]}",
      "twitterReply": "{\"errors\":[{\"message\":\"Could not authenticate you\",\"code\":32}]}"
  }

destroy tweet is not working

I use this code
T.post('statuses/destroy',{id: tweet_id}, function(err, reply) {
console.log(err);
})
and get
{ statusCode: 404,
data: '{"errors":[{"message":"Sorry, that page does not exist","code":34}]}',
twitterReply: '{"errors":[{"message":"Sorry, that page does not exist","code":34}]}' }

stream callbacks on reconnect

Hi!

Just a question, do we need to add again event callbacks after a reconnection? I mean

  1. stream.stop()
  2. stream.on('tweet', callback_function);
  3. stream.start()

I've noticed that, after stop / start, callbacks are not fired. Don't know if I'm doing something wrong, btw!

How do you post on behalf of user?

I'm not seeing anything glaringly obvious in the README on how to post a status on behalf of another user. According to twitter there has to be a 'Sign in with Twitter' feature to achieve this.

Please help! Thanks in advance!

Can't get site streams to work

Hi,

This likely isn't a bug, but just in case I thought I'd ask.

I can get 'user' and public timeline streams to work no problem. But I can't seem to get site streams to work. Have you tested this and gotten it to operate correctly? If so is there something I am doing wrong that is preventing me from getting any events?

Here's what I'm doing...

-Creating an instance of Twit
-Using the app owner's token/secret as well as the app's consumer key/secret
-I starting a 'site' stream as below following users that have authenticated with my app

T.stream('site', {'follow': userIds.join(',')}, function (stream) {
stream.on('tweet', function (tweet) {
console.log(tweet);
}
})

But I get nothing when I tweet from one of my test user accounts. If however, I change 'site' to 'user' or 'statuses/filter', I get the update right away.

What am I doing wrong? Thanks in advance for your help and thanks for making this awesome module.

'connect' event doesn't fire on stream initialization

Consider the following test case:

var stream = T.stream('statuses/filter', { track: 'BarackObama'});

stream.on('connect', function (req) {
  // Doesn't work because the event is emitted before the listener starts to listen
});

If you stop and start again the stream, then the 'connect' event is correctly handled.
What about removing the automatic start and call it manually?

Twitter API Connection Errors?

I am having a problem when the Twitter API is down, my whole application crash.
Is there any standar way to deal with connection errors?

Thanks!

posting replies to tweets

Hey sir, I'm trying to make replies, i've tried putting in_reply_to_status_id in the params, but it doesn't seem to be working.

My post looks like this:

T.post('statuses/update', { in_reply_to_status_id: 206921984414724100,  status: '@ABCDominique Great tweet, that.' }, function(err, reply) {
// things
      });

Any ideas?

Reply to tweet is not working

The following code should result in a reply to a post, but it does not. The tweet goes through successfully, but not as a reply. The id used below was taken from the id_str property on the user deacondesperado's tweet. I've included his handle in the status as the api requires.

Any thoughts?

var data = {
    status: "test with @deacondesperado",
    in_reply_to_status_id: 312188548927348737
};
twitter.post "statuses/update", data, function (err, res) {
});

dependency 'mocha' out of date

Mocha dependency is badly out of date and needs updated desperately.

npm WARN engine [email protected]: wanted: {"node":">= 0.4.x < 0.7.0"} (current: {"node":"v0.8.19","npm":"1.2.10"})
npm WARN unmet dependency /home/katana/repos/rumble/node_modules/twit/node_modules/mocha requires commander@'0.3.2' but will load
npm WARN unmet dependency /home/katana/repos/rumble/node_modules/commander,
npm WARN unmet dependency which is version 1.1.1
npm WARN engine [email protected]: wanted: {"node":">= 0.4.x < 0.7.0"} (current: {"node":"v0.8.19","npm":"1.2.10"})
:katana@serenity ~/
$ npm info mocha version
npm http GET https://registry.npmjs.org/mocha
npm http 200 https://registry.npmjs.org/mocha
1.8.1

:katana@serenity ~/
$ npm info mocha dependencies

{ commander: '0.6.1',
  growl: '1.7.x',
  jade: '0.26.3',
  diff: '1.0.2',
  debug: '*',
  mkdirp: '0.3.3',
  ms: '0.3.0' }

Possible memory leak?

I'm noticing something in a simple application that does an interval tweet through twit - and I'm noticing memory use growing over time fairly steadily, making me think something's not being deallocated or gc'd when it should be.

Rough code (with some redacted for own reasons):

var crypto = require('crypto'),
        twit = require('twit'),
        twitter = new twit({
                consumer_key: '',
                consumer_secret: '',
                access_token: '',
                access_token_secret: ''
        }),
        interval = 15 // interval in minutes

// ---

numbers = function(twitter) {
        this.twitter = twitter
        this.intervalFn = null
}
numbers.prototype.run = function() {
        this.twitter.post('statuses/update', { status: 'TRN {' + this.getNumbers() + '} ENDTRN' }, this.react.bind(this))
}
numbers.prototype.react = function(err, reply) {
        if(err) return this.handleError(err)
        console.log('Tweet: ' + (reply ? reply.text : reply))
}
numbers.prototype.handleError = function(err) {
        console.error('response status:', err.statusCode)
        console.error('data:', err.data)
}
numbers.prototype.getNumbers = function() {
        // redacted
}

// ---

n = new numbers(twitter)
n.run()
n.intervalFn = setInterval(n.run.bind(n), (interval) * 60 * 1000)

After few days, it ends up doubling in memory use - after a week, more than tripling.

Search and count

Hi, is there a way to get more than 15 tweets from search? In Twitter documentation user supposed to use "count". I tried it with twit but it does not work.

Proxy support

Hi!

Twit is very cool indeed. However, I seem to have a problem in dev environment and I should use http(s) proxies. This doesn't connect and I think it's because the system proxies are not recognized by node.js. Any chance to add support for proxies (maybe optional params through conf)?

Different results in search/tweets and at twitter.com

I get different results by using "search/tweets" and at twitter.com.
What can be the reason for this behavior?

var Twit = require('twit');
var T = new Twit({
    consumer_key: '...',
    consumer_secret: '...',
    access_token: '...',
    access_token_secret: '...'
});
//  search twitter for all tweets containing the word 'banana' since Nov. 11, 2011
T.get('search/tweets', { q: query + ' since:2006-11-11', count: 100 }, function (err, reply) {
    callBack(null, reply.statuses);
});

Question: access to rate limit information when using REST API

When you call the Twitter REST API it provides rate limiting headers in the response. See: https://dev.twitter.com/docs/rate-limiting-faq#checking

This information looks like it's actually a bit out of date. It looks like the headers are:

  • x-rate-limit-limit
  • x-rate-limit-remaining
  • x-rate-limit-reset

e.g.

{ 'x-access-level': 'read-write',
     'content-type': 'application/json;charset=utf-8',
     'last-modified': 'Sun, 13 Jan 2013 17:29:54 GMT',
     expires: 'Tue, 31 Mar 1981 05:00:00 GMT',
     pragma: 'no-cache',
     'cache-control': 'no-cache, no-store, must-revalidate, pre-check=0, post-check=0',
     'set-cookie':
      [ 'guest_id=v1%3A135809819409692422; Expires=Tue, 13-Jan-2015 17:29:54 GMT; Path=/; Domain=.twitter.com',
        'lang=en' ],
     'x-transaction': '53a1e38afc6f4623',
     'x-frame-options': 'SAMEORIGIN',
     status: '200 OK',
     date: 'Sun, 13 Jan 2013 17:29:54 GMT',
     'content-length': '4171',
     'x-rate-limit-limit': '180',
     'x-rate-limit-remaining': '175',
     'x-rate-limit-reset': '1358098325',
     server: 'tfe',
     connection: 'close' }

This information might be quite useful to those using this library e.g. knowing when to back off calls when approaching the rate limit. Any thoughts on providing access to this? It could be as simple as passing on the response object as part of the callback here:
https://github.com/ttezel/twit/blob/master/lib/oarequest.js#L199

A developer could then just access the third parameter on any get or post call e.g.

T.get('search/tweets', { q: 'banana since:2011-11-11' }, function(err, reply, response) {
  var rateLimit = response.headers['x-rate-limit-limit'];
});

Or there may be a nicer solution? Any preferences or thoughts? Happy to submit a pull request if others think this would be handy. I do :)

Update:

It looks like you can't rely on these headers always being present. They are their for search/tweet but not there for others e.g. friendships/destroy. So, it seems inconsistent.

error timestamp

Hi..I'm getting a error about timestamp, apparently (i did a request for twitter time server) and my machine is 5 hour delayed with the twitter service...I change the time but it doesn't works...now..I read here https://dev.twitter.com/discussions/686 than I can change the oauth_timestamp, is possible do it with twit or I need change the source code :S ...I'm pretty newbie with the twitter api..so..if you can help me I appreciate it :D...

Çoklu status/filter stream

Selamlar,

Tek bir connection üzerinden birden fazla status/filter stream yapmaya çalışıyorum ancak başarılı olmuyor. Bu ya da buna en yakın bir kullanım örneği gösterebilir misiniz?

Teşekkürler.

Warning: may need to force use of SSLv3 on some systems for https twitter connections

For some reason, I had an install (on my own server, running Arch) suddenly stop working after restarting the twit-based client I had running - after a bit of work, found it was due to SSL hooliganery.

Symptom is that of a constant reconnection attempts, progressively getting longer (while making no connection in the end), with no real error shown by twit, nor with any hope of making a connection. You can confirm if this is the same problem if - when you try firing a curl request to twitter's API, you're given a curl ssl error similar to curl: (35) error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure. If this is the case, retry the curl request with the -3 flag and see if you get an HTTP 401 response from twitter. If you do, see below for the solution.

Solution:

https.globalAgent.options.secureProtocol = 'SSLv3_method'

Ugly solution, I know. I'm trying to see if this is due to a package update on my end - possibly relating to openssl.

Possible culprits include:

[2013-02-16 13:52] upgraded curl (7.28.1-1 -> 7.29.0-2)
[2013-02-16 13:52] upgraded gnutls (3.1.7-1 -> 3.1.8-1)
[2013-02-16 13:52] upgraded nodejs (0.8.18-2 -> 0.8.19-1)
[2013-02-16 13:52] upgraded openssl (1.0.1.c-1 -> 1.0.1.e-1)

Latest pull off of npm has a bug (at least it would not run for me)

You have a typo at the top of this file. It is ./Auth but the file is auth.js so it throws an error which stops crashes node due to require :)

./node_modules/twit/lib/twitter.js

** Old: **
//
// Twitter API Wrapper
//
var Auth = require('./Auth')
, OARequest = require('./oarequest')

** New: **
//
// Twitter API Wrapper
//
var Auth = require('./auth')
, OARequest = require('./oarequest')

Bad type checks

Was perusing your code and noticed a couple of potential bugs. Just giving a friendly heads up that there a couple of type checks that won't work the way one would expect in JavaScript here and here.

> typeof null
"object"

Streaming API silently not working

Hello there, (yesterday it worked, but I tried today and it didnt, I didnt change anything in the code),

here is my code:

var Twit = require('twit');
var T = new Twit({
consumer_key: 'vroFy2FvOR8En7saib1A4Q'
, consumer_secret: '**'
, access_token: '10818002-
'
, access_token_secret: '*'
});

var stream = T.stream('statuses/sample');
stream.on('tweet', function (tweet) {
console.log(tweet);
});
stream.on('error', function (tweet) {
console.log(tweet);
});

stream.on('limitation', function (tweet) {
console.log(tweet);
});

if I do node twit.js I get nothing and the process ends, any hints?

Error in Twit ID

Looks like because of the way Node.js handle big integers, there is a problem with the Twit ID you received.

I am getting

id_str: '249992494792818688',
id: 249992494792818700,

Any idea of how to solve it?

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.