Advertisement
Guest User

Untitled

a guest
May 18th, 2011
1,395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //uses https://github.com/ciaranj/node-oauth/wiki/Example-usage-example-for-Tweeting-with-Twitter
  2. var OAuth= require('./lib/oauth').OAuth;
  3. var http = require('http');
  4. http.createServer(function (req, res) {
  5.  
  6.  
  7.   console.log("req handled" + req.url);
  8.  
  9.   var u = require('url').parse(req.url, true);
  10.  
  11.   if(u.query.q)
  12.   {
  13.     console.log("tweet: " + u.query.q);
  14.     oAuth= new OAuth("http://twitter.com/oauth/request_token",
  15.                  "http://twitter.com/oauth/access_token",
  16.                  "twitterConsumerKey",  "twitterConsumerSecret",
  17.                  "1.0A", null, "HMAC-SHA1");      
  18.     oAuth.post("http://api.twitter.com/1/statuses/update.json", "twitterAccessToken",
  19.                            "twitterAccessTokenSecret", {"status": u.query.q}, function(error, data) {
  20.                              if(error) console.log(require('sys').inspect(error))
  21.                              else console.log("Tweet success")
  22. });
  23.  
  24. res.writeHead(302, {'Location': 'http://www.google.com/#sclient=psy&q='+u.query.q});
  25.   res.end('\n');
  26.   }
  27.   else
  28.   {
  29.     res.writeHead(200, {'Content-Type': 'text/plain'});
  30.     res.end('It broke... :/ \n');
  31.   }
  32.  
  33.  
  34.  
  35. }).listen(25252);
  36. console.log('Server running on 25252');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement