Easy peasy twitter client for connect
JavaScript
Switch branches/tags
Nothing to show
Pull request Compare This branch is 13 commits ahead, 13 commits behind masylum:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
Readme.md
index.js
package.json

Readme.md

twitter-js

Fork Info

This is a hacked up version of masylums twitter-js with the request/response/session dependencies removed from the twitterclient class. It's still probably broken and you likely want to use masylum's original instead. http://github.com/masylum/twitter-js

Easy peasy twitter client for connect.

npm install twitter-js

Usage

twitter-js has two methods.

  • getAccesToken(req, res, callback): Uses oAuth module to retrieve the access_token
  • apiCall(http_method, path, params, callback): Does a call to twitter API.

Params must contain the token.

Example using express.js

var express = require('express'),
    connect = require('connect');

var twitterClient = require('./../')('yourKey', 'yourPass', 'http://twitter-js.com:3003/'),
    app = express.createServer(
      connect.bodyDecoder(),
      connect.cookieDecoder(),
      connect.session()
    );

app.get('/', function (req, res) {
  twitterClient.getAccessToken(req, res, function (error, token) {
    res.render('client.jade', {locals: {token: token}});
  });
});

app.post('/message', function (req, res) {
  twitterClient.apiCall('POST', '/statuses/update.json',
    {token: {oauth_token_secret: req.param('oauth_token_secret'), oauth_token: req.param('oauth_token'), status: req.param('message')}},
    function (error, result) {
      res.render('done.jade');
    }
  );
});

app.listen(3003);

Test

To test and see this module working:

  • copy the test folder
  • set up the keys and password of your app
  • run it node test/client.js
  • Add 127.0.0.1 twitter-js.com at your hosts file
  • Open your browser at localhost:3003