Skip to content

Commit

Permalink
twit module added for oauth and posting tweet
Browse files Browse the repository at this point in the history
  • Loading branch information
avichalp committed Oct 14, 2014
1 parent c8f0ffc commit 2639a83
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lastestPostedDate.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Thu Mar 29 2012 10:53:23 GMT+0100 (BST)
Tue Oct 14 2014 15:38:45 GMT+0530 (IST)
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"mime" : "1.2.x",
"oauth" : "0.9.x",
"qs" : "0.4.x",
"request" : "2.9.x"
"request" : "2.9.x",
"twit" : ""
},
"devDependencies": {},
"optionalDependencies": {},
Expand Down
46 changes: 21 additions & 25 deletions rss_app.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
var request = require('request'),
url = require('url'),
htmlparser = require('htmlparser'),
fs = require('fs'),
OAuth = require('oauth').OAuth;
url = require('url'),
htmlparser = require('htmlparser'),
fs = require('fs'),
Twit = require('twit');

// Config variables
var rssUrl = 'http://feeds.bbci.co.uk/news/rss.xml';
var intervalLength = 2000;

// Setup vars for twitter posting
var twitterConsumerKey = 'add your key here';
var twitterConsumerSecret = 'add your secret here';
var twitterAccessToken = 'add your token here';
var twitterAccessTokenSecret = 'add your token secret here';
var twitterConsumerKey = '...';
var twitterConsumerSecret = '...';
var twitterAccessToken = '...';
var twitterAccessTokenSecret = '...';

oAuth= new OAuth("http://twitter.com/oauth/request_token",
"http://twitter.com/oauth/access_token",
twitterConsumerKey,
twitterConsumerSecret,
"1.0A",
null,
"HMAC-SHA1"
);
var twitter = new Twit({
consumer_key: twitterConsumerKey
, consumer_secret: twitterConsumerSecret
, access_token: twitterAccessToken
, access_token_secret: twitterAccessTokenSecret
});

// Get date of latest posted article
var lastestPostedItemDate = getLatestPostedItemDate();
Expand Down Expand Up @@ -60,15 +58,13 @@ function setLatestPostedItemDate(date){
function publishToTwitter(item){
var tweet = item.title + ' ' + item.link;
console.log('publishing to twitter');
oAuth.post('http://api.twitter.com/1/statuses/update.json',
twitterAccessToken,
twitterAccessTokenSecret,
{'status': tweet},
function(error, data) {
if(error) console.log(require('util').inspect(error))
//else console.log('succcess!' + data)
});
//

twitter.post('statuses/update', { status: tweet }, function(err, data, response) {
if (err)
console.log(err);
console.log(data);
});

}

// looping on the server (every second)
Expand Down

0 comments on commit 2639a83

Please sign in to comment.