Example usage example for Tweeting with Twitter

jhermsmeier edited this page Mar 20, 2012 · 1 revision

This example assumes that you have already got hold of a valid twitter OAuth accesstoken and OAuth token secret. This can be done either by using the node-oauth library to perform the usual workflow, or by using the 'my access token' functionality that twitter provides.

var OAuth= require('./lib/oauth').OAuth;

oAuth= new OAuth(
  "http://twitter.com/oauth/request_token",
  "http://twitter.com/oauth/access_token", 
  twitterConsumerKey, twitterConsumerSecret, 
  "1.0A", null, "HMAC-SHA1"
);

oAuth.post(
  "http://api.twitter.com/1/statuses/update.json",
  twitterAccessToken, twitterAccessTokenSecret,
  {"status":"Need somebody to love me!"},
  function(error, data) {
    if(error) console.log(require('sys').inspect(error))
    else console.log(data)
  }
);