Log in Register

Log in

How to auto-follow, auto-comment and auto-like a post on Instagram Page with PHP/cURL (2)


In the last article, I use a script to autopost image to Instagram. In this article, here is a script to auto-follow, auto-like and auto-comment a batch of Instagram posting based on specific tag search results.
You need to set a group of targeted tag (or keywords). The script will randomly pick up one tag each time and search for most recent postings with this tag. To avoid being detected by Instagram, the script will only auto-follow, auto-like and auto-comment not more than 40 (you can set your number in the script) postings each batch.
Owners of the posting with high like count (example 300 like count) most likely NOT interested to know who come to like their postings. So to get the best results from the script, the code will avoid postings that already have high like count and only like those postings with like count less than 20 (you can set your number in the script). This is to get the attention of the posting owners so that they can take next cause of action, such as follow you back or say thank you to your comment. As such, your followers will increase. I will show you the results in the last part of this article.
If you are already following a user, the script will not follow that user again. It will then only like the posting of that user. This is to avoid the same user sees repeating comment from us.

So if you like what the script can do for you, here is the code!


** You need to Register before download this file.

There are three files in this tutorial.

1. instagram_config.php

$searchtag = array(


This is where you set of all your targeted Instagram tags. I set four tags in this example. You should add more. I have more than 150 tags in my actual file.

2. instagram.class.php
This is the file you don't have to make any changes. It contains class for you to login Instagram, search tag, check your relationship with the posting's owner, auto follow new user, auto like and auto comment the posting.

public function Login($username, $password) {
$this->username = $username;
$this->password = $password; 
$this->guid = $this->GenerateGuid();
$device_id = "android-" . $this->guid; 
$data = '{"device_id":"'.$device_id.'","guid":"'.$this->guid.'","username":"'. $this->username.'","password":"'.$this->password.'","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}';
$sig = $this->GenerateSignature($data);
$data = 'signed_body='.$sig.'.'.urlencode($data).'&ig_sig_key_version=6'; 
$myid = $this->Request('accounts/login/', true, $data, false); 
$decode = json_decode($myid[1], true); 
$this->my_uid = $decode['logged_in_user']['pk'];
return $myid;


Use your username and password to login to Instagram.

$this->Request('accounts/login/', true, $data, false); 


This is the private API for Instagram login.

public function SearchTag($tag) {
$device_id = "android-".$this->guid;
$data = '{"device_id":"'.$device_id.'","guid":"'. $this->guid .'","timezone_offset":"43200","uid":"'.$this->my_uid.'","q":"'.$tag.'","count":"50","source_type":"5","filter_type":"0","extra":"{}","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}'; 
$sig = $this->GenerateSignature($data);
$new_data = 'signed_body='.$sig.'.'.urlencode($data).'&ig_sig_key_version=6'; 
return $this->Request('feed/tag/'.$tag.'/', true, $new_data, true); 


SearchTag object will take one tag and return the most recent 50 image postings.

public function IsFriend($user_id) {
$device_id = "android-".$this->guid;
$data = '{"device_id":"'.$device_id.'","guid":"'. $this->guid .'","uid":"'.$this->my_uid.'","module_name":"feed_timeline","user_id":"'.$user_id.'","source_type":"5","filter_type":"0","extra":"{}","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}'; 
$sig = $this->GenerateSignature($data);
$new_data = 'signed_body='.$sig.'.'.urlencode($data).'&ig_sig_key_version=6';
return $this->Request('friendships/show/'.$user_id.'/', true, $new_data, true); 


For each image posting, we check if you have already following the owner.

public function PostFollow($user_id) {
$device_id = "android-".$this->guid;
$data = '{"device_id":"'.$device_id.'","guid":"'. $this->guid .'","uid":"'.$this->my_uid.'","module_name":"feed_timeline","user_id":"'.$user_id.'","source_type":"5","filter_type":"0","extra":"{}","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}'; 
$sig = $this->GenerateSignature($data);
$new_data = 'signed_body='.$sig.'.'.urlencode($data).'&ig_sig_key_version=6';
return $this->Request('friendships/create/'.$user_id.'/', true, $new_data, true); 


This is the request to auto-follow a user.

public function PostComment($caption, $media_id) {
$caption = preg_replace("/\r|\n/", "", $caption);
$device_id = "android-".$this->guid;
$data = '{"device_id":"'.$device_id.'","guid":"'. $this->guid .'","uid":"'.$this->my_uid.'","comment_text":"'.trim($caption).'","source_type":"5","filter_type":"0","extra":"{}","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}'; 
$sig = $this->GenerateSignature($data);
$new_data = 'signed_body='.$sig.'.'.urlencode($data).'&ig_sig_key_version=6';
return $this->Request('media/'.$media_id.'/comment/', true, $new_data, true); 


The is the request to auto-comment on the image posting.

public function PostLike($media_id) {
$device_id = "android-".$this->guid;
$data = '{"device_id":"'.$device_id.'","guid":"'. $this->guid .'","uid":"'.$this->my_uid.'","module_name":"feed_timeline","d":"0","source_type":"5","filter_type":"0","extra":"{}","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}'; 
$sig = $this->GenerateSignature($data);
$new_data = 'signed_body='.$sig.'.'.urlencode($data).'&ig_sig_key_version=6';
return $this->Request('media/'.$media_id.'/like/', true, $new_data, true); 


This is the request to auto-loke the image posting.

3. instagram_follow.php
This is the main file of the script. You can set cron job to run this file every few hours. I set to 6 hours each day, so my server will run this script 4 times per day.
You need to set your Instagram username and password here so that the script will login for you. Then it will randomly pull one of the tags and search for image postings come with this tag. It then checks had you already followed the owner of each posting. If not follow yet, then auto-follow this person, auto-like and auto-comment on his/her post.

$username = 'xxxx'; // your username
$password = 'yyyy'; // your password


Enter your username and password here.

$response = $insta->Login($username, $password);


So first we login into Instagram.

$search = $searchtag[array_rand($searchtag)];
$res = $insta->SearchTag($search);


We randomly select one of the targeted tag in the array and get most recent postings which carry the tag.

if ($i<40) {
if ($like_count < 20 ) {
$fakecomment = $hello[array_rand($hello)].' '.'@'. $username . '' . $praise[array_rand($praise)];


To avoid detection, the script will process 40 images each time. If you are aggressive, then can set to a higher number. Again, I take no responsibility if your account banned by Instagram. :)

We also target for image posting with low like count to get attention from image owner. In this case, less than 20.
Then we construct fake comment such as
Hi @xxxx, so nice or
Hello @yyyy, great stuff or
@zzzz, cool picture etc.

if (!$friend['following'] && !$friend['is_private'] && !$friend['outgoing_request']) {
echo "<br> after follow";
if (!$haslike) {
echo "<br> All auto comment, post, Like";
$res=$insta->PostComment($fakecomment, $media_id); 


Then we check our relationship with the image posting owner. If we had not followed this user before, or his/her account is not private and we never send follow request before, and we have not like this image posting, then request auto-follow, auto-like and auto-comment. The is a random 3 to 10 seconds of delay between each action to avoid detection by Instagram.

} else {
if (!$haslike) {
echo "<br> Like only";


Lastly, if we had followed this person already, then just like the post. No more fake comment.

So here's the results.

auto following

After running the script, check the new following.  You should see some new faces.

autofollow results1

In one of the new following, check the most recent posting of this user. You should able to find the tag ("Instagram" in this case), your fake comment and the like on this post.


autofollow results2

Same thing on another following.


reaction from users

Wait for a while. Because we follow, post a comment and like their posting, some users are kind enough to like back our posting, as well as thanks us. Happy!?

followers before autofollow

My followers and following a month plus ago. Then I run auto-post and auto-follow script for 1.5 months.

followers after autofollow

Ahh, let you see the bigger picture. (oopp, I changed the display language)

So good luck everyone! Happy instagram!

Last modified on Saturday, 26 November 2016 16:25
Rate this item
(0 votes)

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.

Anti-spam: complete the task
back to top