Skip to content

Instantly share code, notes, and snippets.

@emirchus
Created October 19, 2022 03:00
Show Gist options
  • Save emirchus/002c0bd0a15364f093da3a261ebb1b99 to your computer and use it in GitHub Desktop.
Save emirchus/002c0bd0a15364f093da3a261ebb1b99 to your computer and use it in GitHub Desktop.
Comments users on an instragram post.
/**
* How to use
* 1. Open developer tools in browser
* 2. Go to network tab
* 3. Go to the post you want to comment and post a comment
* 4. Search for the request called "add" and copy the cookies, csrf token, app id, www claim, asbd id and post id
* 5. Paste the cookies, csrf token, app id, www claim, asbd id and post id in the variables
* 6. Paste the users in the users array
* 7. Run the script.
*
* Happy commenting 🥰
*/
const axios = require("axios");
const users = []; //All users to be tagged
const usersChunck = chunk(users, 2); //Users chunked into arrays of 2
function chunk(list, size) {
const chunks = [];
for (let i = 0; i < list.length; i += size) {
chunks.push(list.slice(i, i + size));
}
return chunks;
}
let lastIndex = 0;
async function init() {
console.log("Starting");
const chunkUsers = usersChunck[lastIndex].map((user) => `@${user}`).join(" ");
console.log("Sending", chunkUsers);
let cookies = ""; //Cookies copied from browser <cookie>
let Cookies = ""; //Cookies copied from browser <Cookie>
let csrftoken = ""; //csrf token copied from browser <x-csrftoken>
let appId = ""; //app id token copied from browser <x-ig-app-id>
let wwwClaim = ""; //claim token copied from browser <x-ig-www-claim>
let asbdId = ""; //asbd id token copied from browser <x-asbd-id>
const postId = ""; //Post id copied from browser request
var options = {
method: "POST",
url: `https://i.instagram.com/api/v1/web/comments/${postId}/add/`,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
cookie: cookies,
Cookie: Cookies,
"x-csrftoken": csrftoken,
"x-ig-app-id": appId,
"x-ig-www-claim": wwwClaim,
"x-asbd-id": asbdId,
"user-agent":
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36",
"sec-fetch-mode": "cors",
},
data: { comment_text: chunkUsers },
};
axios
.request(options)
.then(function (response) {
console.log(response.data);
lastIndex++;
setTimeout(() => {
init();
}, 5000);
})
.catch(function (error) {
console.error(error.data);
});
}
init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment