build your own instagram bot from scratch (or) set one up in like 10s for free
a brief overview of this blog post: {% embed https://www.youtube.com/watch?v=Wr-6jx4DILA %}
Introduction
Imagine you have a cool meme page on instagram with about a 1M+ followers and the best part - you never really need to interfere with itā¦
not kiddingā¦ but well there sure is a catch here cuz otherwise 1M+ followers would not longer be a feat anymore:
any page on instagram/social media in general has got 2 aspects to it:
- content creation šØ
- marketing š¢
this bot system has got your back for content creation and youāve gotta take care of the marketing and making sure the page growsā¦
hereās an example of a successfully automated meme page w/ poor marketing: @taewonsu
and Iāve really gotta mention I absolutely suck at marketing and henceā¦ and yea obviously @taewonsu is my automated instagram meme page
So What Exactly Does The Bot Do
doesnāt matter if youāre a human or a bot(AI), creating memes people ā¤ļø is tough
butā¦ there exists reddit, the front page of the internet this is where memes first hit the internet and then they trickle down to instagram/facebook/twitter/discord
and most people shamelessly just steal memes from reddit (i.e. they do not credit the original creator of the meme)
that however that doesnāt apply to a bot soā¦ itāll will credit the original u/creator
of the meme and then just post the meme to our page
Creating Your Own Bot
This is your last chance, after this thereās no turning back.
- you take the blue pillā¦ I give you the easy wayā¦ setting up a meme bot from my source code.
- you take the red pillā¦ I show you how the bot works and how you can build your bot from scratch.
Blue Pill
{% embed https://youtu.be/Q9vDaU8piKc %}
- clone this repository off github
- create an instance on heroku (or) whatever
- configure the environment variables for your bot
- GG
Red Pill
the bot does 3 thing:
- scrape for top memes of the day in the specified
r/subreddit
- check if a meme has been previously posted
- post the unique memes to
instagram
1. Scraping
working with redditās API has been an absolute pleasure
letās say the URL for top content in a subreddit say r/animemes
is https://www.reddit.com/r/Animemes/top/
then the endpoint for the API would be https://www.reddit.com/r/Animemes/top.json
so fetching the top 3 memes of the day would be:
// fetching new memes from reddit
const res = await axios.get(`https://www.reddit.com/r/${subreddit}/top.json?limit=${top_x ? top_x : 3}`);
animemes = res.data.data.children;
2. Unique
when weāre posting a bunch of memeās per day itāll be pretty likely that we may re-post something
so the bot maintains an hashmap, where the key is the id
of the meme in redditās database and the value is the meme data
when ever it gets a new meme, it quickly checks if the id exists in the hashmap, if it doesnāt the bot posts the meme and then adds the meme to the hashmap
// fetching past memes
const raw_pa = fs.readFileSync(posted_animemes_location);
const posted_animemes: animeme_in_json = JSON.parse(raw_pa.toString());
// cross-referencing a new meme
if (posted_animemes[animeme.data.id]) {
console.log("seen this!");
return null;
}
3. Posting
while building the bot, I was pleasantly surprised at how less bug I was running into and Iām not gonna lie it did feal really goodā¦ and then instagram API happened interacting with instagramās API was an absolute pain in the assā¦ spent like 3 days and I still couldnāt properly set up the access tokens required
luckily I found a god send instagram-private-api
instagram-private-api is basically a typescript š¤© wrapper over instagramās private API [the endpoints youād find if you inspected the network panel of your browserās dev tools] instagram-private-api greatly sped up and made the developer experience just way more greater and I was able to implement the auto post to insta reletively quickly
// logging into instagram
try {
const auth = await ig.account.login(ig_uname, ig_pass);
if (!auth.pk) return "LOGIN FAILED";
} catch (error) {
console.log(error);
return "LOGIN BLOCKED";
}
// uploading an meme
try {
const publishResult = await ig.publish.photo({
file: imageBuffer,
caption: `credits: u/${animeme_to_post.author}\n${animeme_to_post.title} ĀÆ\\_(ć)_/ĀÆ\n.\n.\n.\n.\n.\n#${hashtags}`,
});
} catch (error) {
console.log("work on fixing that image size thing you sucker");
}
the best thing here is since weāre basically using instagram-private-api, instagram canāt really recognize us a bot
and thatās how I built an automated instagram meme page from scratch
If You ā¤ļø This Blog Post Be Sure To Drop a DM on Twitter
also hereāre all the links throughout the blog post og automated bot @taewonsu: https://www.instagram.com/taewonsu/ source code on github: https://github.com/LucidMach/taewonsu my twitter: https://twitter.com/lucidmach
āļø, LucidMach
untill next time !ļø ā
or you could spot me in the wild š¤ i mean instagram, twitter, linkedin and maybe even youtube where i excalidraw those diagrams