Created
April 6, 2016 22:45
-
-
Save jaredpalmer/138f17a142d2d8770a1d752b0e00bd31 to your computer and use it in GitHub Desktop.
send-tweet.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Code snippet for posting tweets to your own twitter account from node.js. | |
* You must first create an app through twitter, grab the apps key/secret, | |
* and generate your access token/secret (should be same page that you get the | |
* app key/secret). | |
* Uses oauth package found below: | |
* https://github.com/ciaranj/node-oauth | |
* npm install oauth | |
* For additional usage beyond status updates, refer to twitter api | |
* https://dev.twitter.com/docs/api/1.1 | |
*/ | |
var OAuth = require('oauth'); | |
var twitter_application_consumer_key = ''; // API Key | |
var twitter_application_secret = ''; // API Secret | |
var twitter_user_access_token = ''; // Access Token | |
var twitter_user_secret = ''; // Access Token Secret | |
var oauth = new OAuth.OAuth( | |
'https://api.twitter.com/oauth/request_token', | |
'https://api.twitter.com/oauth/access_token', | |
twitter_application_consumer_key, | |
twitter_application_secret, | |
'1.0A', | |
null, | |
'HMAC-SHA1' | |
); | |
var status = ''; // This is the tweet (ie status) | |
var postBody = { | |
'status': status | |
}; | |
// console.log('Ready to Tweet article:\n\t', postBody.status); | |
oauth.post('https://api.twitter.com/1.1/statuses/update.json', | |
twitter_user_access_token, // oauth_token (user access token) | |
twitter_user_secret, // oauth_secret (user secret) | |
postBody, // post body | |
'', // post content type ? | |
function(err, data, res) { | |
if (err) { | |
console.log(err); | |
} else { | |
// console.log(data); | |
} | |
}); |
This is exacly what I needed thanks!
this code came as a blessing to me, hope you have a good day :)
I SOO NEEDED THISSS
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do I modify this to send tweets with image attachments?