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:
  1. You need to have a twitter app registered
  2. You know your apps 'consumer_key'
  3. You know your apps 'consumer_secret'
  4. You know your accounts 'access_token_key'
  5. You know your accounts 'access_token_secret'.
  6. You have basic Javascript experience.
  7. You have basic Nodejs + NPM experience.
  8. You know how to add words into a document.
If any of that sounds like its too much for you, you're out of luck because I don't have time to hold your hand and f*** you calm. Were going full speed through this, these steps are going to be short and sweet, and here they are.

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.

Webp.net-resizeimage.gif


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:
Nothing like a first post to show the forum that you're an asshole! "No time to hold hands".

Are you serious?

Plus there are apps that fav every tweet already, not 1 out of 10.
 
Nothing like a first post to show the forum that you're an asshole! "No time to hold hands".

Are you serious?

Plus there are apps that fav every tweet already, not 1 out of 10.

You seem triggered over nothing.
F*** me for sharing, all I was trying to do was speed along the read...

"Plus there are apps that fav every tweet already, not 1 out of 10"
You can't even say that this won't fav every tweet, because if you follow everyone that posts frequently in your niche, it will fav every post...

I inferred in the post that the code needs to be tuned to your niche or the niche tuned to the code.

Twitter accounts get rate limited... and the 'crypto' status stream moves quick, it wouldn't make sense to favorite every one.
 
Here is a version of the same code above, but for the post it favs if you're not following the user who made the post, it follows them.

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 followPromise = (twitterClient, accountId) => {
    return new Promise((resolve, reject) => {
        twitterClient.post('friendships/create.json', { user_id: accountId }, (error, body, response) => {
            if (error) {
                reject(error);
            } else {
                twitterClient.followingIds.push(accountId);
                resolve(`${body.name} has just been followed.`);
            }
        });
    });
};
const favoriteFollowYourNiche = 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_str) !== -1 || every10thTweet === 10) {
                    every10thTweet = 0;
                    if (yourTwitterClient.followingIds.indexOf(tweet.user.id_str) === -1) {
                        followPromise(yourTwitterClient, tweet.user.id_str).then(out => {
                            console.log(out);
                        }).catch(err => { console.log(err); });
                    }
                    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); });
};
favoriteFollowYourNiche('crypto');

followfavyourniche.gif

I had this running for hours without any kind of rate limiting untill I hit the supposive ~1000 requests in a 24hr time span limit.
 
Back
Top
AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features and essential functions on BlackHatWorld and other forums. These functions are unrelated to ads, such as internal links and images. For the best site experience please disable your AdBlocker.

I've Disabled AdBlock