antiClergy
Newbie
- Joined
- Jul 11, 2017
- Messages
- 6
- Reaction score
- 0
Hello BHW.
I want my first post to be something special, so I'd like to share some code with you guys!
If you meet the 8 key prerequisites and can get through the 7 easy steps to success listed below, you will be on your way to favoriting (1 out of 10) current posts in your niche + favoriting every current post from whom you follow that are posting in your niche!
First off, the prerequisites:
STEP ONE: MAKE A DIRECTORY.
STEP TWO: NPM INSTALL TWITTER.
STEP THREE: CODE.
STEP FOUR: EDIT LINES 3-6 IN THE CODE ABOVE.
STEP FIVE: RUN NODE ON THAT CODE.
STEP SIX: ???.
STEP SEVEN: PROFIT.
To have this code work for your specific niche, edit line 52.
Change 'crypto' to whatever your niche is.
Keep in mind if your niche is dry you might need to find something more popular.
Also if your niche is too popping, you could hit a rate limit.
And... Uhh... thats basicly it...
Let me know what you think below, and let me know if you were able to get the favorites rolling in.
In my next post I will share with you my follow/unfollow management scripts.
I want my first post to be something special, so I'd like to share some code with you guys!
If you meet the 8 key prerequisites and can get through the 7 easy steps to success listed below, you will be on your way to favoriting (1 out of 10) current posts in your niche + favoriting every current post from whom you follow that are posting in your niche!
First off, the prerequisites:
- You need to have a twitter app registered
- You know your apps 'consumer_key'
- You know your apps 'consumer_secret'
- You know your accounts 'access_token_key'
- You know your accounts 'access_token_secret'.
- You have basic Javascript experience.
- You have basic Nodejs + NPM experience.
- You know how to add words into a document.
STEP ONE: MAKE A DIRECTORY.
STEP TWO: NPM INSTALL TWITTER.
STEP THREE: CODE.
Code:
const Twitter = require('twitter');
let yourTwitterClient = new Twitter({
consumer_key: '',
consumer_secret: '',
access_token_key: '',
access_token_secret: ''
});
yourTwitterClient.followingIds = [];
const updateFollowingIdsPromise = (twitterClient) => {
return new Promise((resolve, reject) => {
twitterClient.get('friends/ids.json', (error, body, response) => {
if (error) {
reject(error);
} else {
twitterClient.followingIds = body.ids;
resolve('updated');
}
});
});
};
const favoritePromise = (twitterClient, postId) => {
return new Promise((resolve, reject) => {
twitterClient.post('favorites/create.json', { id: postId }, (error, body, response) => {
if (error) {
reject(error);
} else {
resolve(`A post has been favorited...`);
}
});
});
};
const favoriteYourNiche = niche => {
updateFollowingIdsPromise(yourTwitterClient).then(out => {
let every10thTweet = 0;
yourTwitterClient.stream('statuses/filter', { track: niche }, stream => {
stream.on('data', tweet => {
every10thTweet = every10thTweet + 1;
console.log('new tweet: ${tweet.id_str}');
if (yourTwitterClient.followingIds.indexOf(tweet.user.id) !== -1 || every10thTweet === 10) {
every10thTweet = 0;
favoritePromise(yourTwitterClient, tweet.id_str).then(out => {
console.log(`favorited tweet: ${tweet.id_str}`);
}).catch(err => { console.log(err); });
}
});
stream.on('error', (error) => {
console.log(error);
});
});
}).catch(err => { console.log(err); });
};
favoriteYourNiche('crypto');
STEP FOUR: EDIT LINES 3-6 IN THE CODE ABOVE.
STEP FIVE: RUN NODE ON THAT CODE.
STEP SIX: ???.
STEP SEVEN: PROFIT.
To have this code work for your specific niche, edit line 52.
Change 'crypto' to whatever your niche is.
Keep in mind if your niche is dry you might need to find something more popular.
Also if your niche is too popping, you could hit a rate limit.
And... Uhh... thats basicly it...
Let me know what you think below, and let me know if you were able to get the favorites rolling in.
In my next post I will share with you my follow/unfollow management scripts.
Last edited: