-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitter.cjs
40 lines (34 loc) · 1.33 KB
/
twitter.cjs
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
39
40
require('dotenv').config()
const { TwitterClient } = require('twitter-api-client')
// This is a simple implementation of the Twitter API. Presumably, this would function the same for other platforms with their implementation
// The "tweet" parameter is just a string
module.exports.main = async function tweet(tweet) {
const twitterClient = new TwitterClient({
apiKey: process.env.TWITTER_API_KEY,
apiSecret: process.env.TWITTER_API_KEY_SECRET,
accessToken: process.env.TWITTER_ACCESS_TOKEN,
accessTokenSecret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
});
twitterClient.tweets.statusesUpdate({
status: tweet
}).then(response => {
console.log("Tweeted! Tweet ID: ", response.id)
}).catch(err => {
console.error(err)
})
}
module.exports.tweet_listing = async function tweet_listing(tweet) {
const twitterClient = new TwitterClient({
apiKey: process.env.TWITTER_API_KEY2,
apiSecret: process.env.TWITTER_API_KEY_SECRET2,
accessToken: process.env.TWITTER_ACCESS_TOKEN2,
accessTokenSecret: process.env.TWITTER_ACCESS_TOKEN_SECRET2,
});
twitterClient.tweets.statusesUpdate({
status: tweet
}).then(response => {
console.log("Tweeted! Tweet ID: ", response.id)
}).catch(err => {
console.error(err)
})
}