|
1 | 1 | // Our Twitter library
|
2 | 2 | const Twit = require("twit");
|
3 | 3 |
|
4 |
| -// We need to include our configuration file |
| 4 | +// We need to include our configuration file... |
5 | 5 | const twit = new Twit(require("./config.js"));
|
6 | 6 |
|
7 |
| -// This is the URL of a search for the latest tweets on the '#MeetMaye' hashtag. |
| 7 | +// This is the URL of a search for the latest tweets on the '#MeetMaye' hashtag... |
8 | 8 | const mediaArtsSearch = { q: "#MeetMaye", count: 100, result_type: "recent" };
|
9 | 9 |
|
10 | 10 | // This function finds the latest tweet with the MeetMaye hashtag and retweets.
|
11 | 11 | const retweetLatest = () => {
|
12 | 12 | twit.get("search/tweets", mediaArtsSearch, (error, data) => {
|
13 |
| - // log out any errors and responses |
14 |
| - console.log(error, data); |
15 | 13 | // If our search request to the server had no errors...
|
16 |
| - if (!error) { |
17 |
| - // ...then we grab the ID of the tweet we want to retweetwit... |
18 |
| - let retweetId = data.statuses[0].id_str; |
19 |
| - // ...and then we tell Twitter we want to retweet it! |
| 14 | + if (error) { |
| 15 | + // However, if our original search request had an error, we want to print it out here... |
| 16 | + console.log(error.message); |
| 17 | + } else { |
| 18 | + // Grab the ID of the tweet we want to retweetwit... |
| 19 | + const retweetId = data.statuses[0].id_str; |
| 20 | + // Tell Twitter we want to retweet it... |
20 | 21 | twit.post("statuses/retweet/" + retweetId, {}, (error, response) => {
|
21 | 22 | if (response) {
|
22 |
| - console.log( |
23 |
| - "Success! Check your bot, it should have retweeted something." |
24 |
| - ); |
| 23 | + console.log("Success! Your bot has retweeted something."); |
25 | 24 | }
|
26 |
| - // If there was an error with our Twitter call, we print it out here. |
| 25 | + // If there was an error with our Twitter call, we print it out here... |
27 | 26 | if (error) {
|
28 |
| - console.log("There was an error with Twitter:", error); |
| 27 | + console.log(error.message); |
29 | 28 | }
|
30 | 29 | });
|
31 | 30 | }
|
32 |
| - // However, if our original search request had an error, we want to print it out here. |
33 |
| - else { |
34 |
| - console.log("There was an error with your hashtag search:", error); |
35 |
| - } |
36 | 31 | });
|
37 |
| -} |
| 32 | +}; |
38 | 33 |
|
39 | 34 | // Try to retweet something as soon as we run the program...
|
40 | 35 | retweetLatest();
|
|
0 commit comments