forked from Team-Masark/nodebot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtweet.js
More file actions
38 lines (29 loc) · 1.04 KB
/
tweet.js
File metadata and controls
38 lines (29 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var Twitter = require('twitter')
//create your application from apps.twitter.com and generate the following keys. They will be something like this:
var client = new Twitter({
consumer_key: 'ROMG2EYTR3ysrZxMDlzz35riF',
consumer_secret: 'Blau4wgGQ06hM2oVvnCACMyLbMS73V5F9Bs44YchZvAvFc1ixq',
access_token_key: '1530705451-jqAavRnuLXQ50vmbFeCe6TZyPTD1gALw7x7QD4N',
access_token_secret: '8zJFNhoYyq9AfDTiDgh50omx3XzK6L25oJBet2ZrKtGqb'
})
// Load your image
var data = require('fs').readFileSync('./temp-img.jpg')
// Make post request on media endpoint. Pass file data as media parameter
client.post('media/upload', {
media: data
}, function(error, media, response) {
if (!error) {
// If successful, a media object will be returned.
console.log(media)
// Lets tweet it
var status = {
status: 'I am a tweet',
media_ids: media.media_id_string // Pass the media id string
}
client.post('statuses/update', status, function(error, tweet, response) {
if (!error) {
console.log(tweet)
}
})
}
})