Log in Register

Log in

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

instagram

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(
'instagram',
'aquamarine',
'wifi', 
'lovestory', 
);

 


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']) {
$res=$insta->PostFollow($user_id);
echo "<br> after follow";
if (!$haslike) {
echo "<br> All auto comment, post, Like";
sleep(rand(3,10));
$res=$insta->PostLike($media_id);
sleep(rand(3,10));
$res=$insta->PostComment($fakecomment, $media_id); 
sleep(rand(3,10)); 
}

 

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";
sleep(rand(3,10));
$res=$insta->PostLike($media_id); 
}

 

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
(1 Vote)

32 comments

  • Fikri Wildan Nugraha

    Hello Chin-Hock can you help me,but system instagram detect it,and just reset my password. is that too fast interval?

    posted by Fikri Wildan Nugraha Monday, 10 April 2017 17:17 Comment Link
  • Chin-Hock Tan

    Hello Fikri,
    If instagram detected you, one of the cause can be your duration between two actions is too short.
    Can change sleep(rand(3,10)) to (10, 20) or longer duration.
    Also, make it random for time interval between cron job by inserting delay at the beginning of the script.
    Good luck ya.

    posted by Chin-Hock Tan Tuesday, 11 April 2017 15:36 Comment Link
  • Fikri Wildan Nugraha

    thank you so much, but it seems my cloud hosting wont let the script long running more than just 1200 , i think i must use localhost. . do you have an idea?

    posted by Fikri Wildan Nugraha Tuesday, 11 April 2017 19:09 Comment Link
  • Fikri Wildan Nugraha

    thank you so much, but it seems my cloud hosting wont let the script long running more than just 1200 , i think i must use localhost. . do you have an idea?

    posted by Fikri Wildan Nugraha Tuesday, 11 April 2017 19:14 Comment Link
  • Chin-Hock Tan

    Hello Fikri,
    This script is design to auto like/follow/comment for less than 40 cycle (I set $i less than 40), meaning every one hour there will be maximum auto like/follow/comment.
    you can set cron job to every 20 minutes and try out.

    posted by Chin-Hock Tan Wednesday, 12 April 2017 15:51 Comment Link
  • Fikri wildan nugraha

    Ok thanks. I will try to learn the script. I still not good on PHP. I think library Curl that used is very interesting.

    posted by Fikri wildan nugraha Thursday, 13 April 2017 06:58 Comment Link
  • ali

    its amazing thank u so much ... i want a script to follow target followers can u make ?

    posted by ali Thursday, 13 April 2017 08:03 Comment Link
  • Chin-Hock Tan

    Ali,
    Interesting. How you define "target followers"?

    posted by Chin-Hock Tan Friday, 14 April 2017 03:07 Comment Link
  • ali

    Chin-Hock Tan,
    for example follows adele followers on instagram
    i have an script that follows the followers of a target in but now it does'nt work you can see it in this link:
    https://alitaran.000webhostapp.com/autofollow.php.zip

    posted by ali Thursday, 20 April 2017 09:39 Comment Link
  • Mathias

    I get this message when I run instagram_follow.php
    Warning: Invalid argument supplied for foreach() in /www/htdocs/********/instagram_follow.php on line 29

    posted by Mathias Thursday, 04 May 2017 11:36 Comment Link
  • Chin-Hock Tan

    Hello Mathias,
    You need to dump the value of the variables to see which location is actually having problems.

    posted by Chin-Hock Tan Saturday, 06 May 2017 08:50 Comment Link
  • Danang

    sir,, why my eror is,,
    Request failed, there's a chance that this proxy/ip is blockedArray ( [0] => 400 [1] => {"message": "Sorry, there was a problem with your request.", "status": "fail", "error_type": "sentry_block"} )

    posted by Danang Wednesday, 10 May 2017 16:50 Comment Link
  • Chin-Hock Tan

    Hello Danang,
    I don't have this problem before. Your problem could be due to blocked IP. You can try to use other IP addresses.

    posted by Chin-Hock Tan Thursday, 11 May 2017 00:56 Comment Link
  • EXECUTOR brandon

    sir,, why my eror is,,
    Request failed, there's a chance that this proxy/ip is blockedArray ( [0] => 400 [1] => {"message": "Sorry, there was a problem with your request.", "status": "fail", "error_type": "sentry_block"} )

    This is because Instagram detected a "bot". aka "sentry" You need to adjust your processes image count to lower than 40. If problem persists then you need to use a different Instagram account. I use the following:
    $i

    posted by EXECUTOR brandon Friday, 19 May 2017 16:00 Comment Link
  • EXECUTOR brandon

    I get this message when I run instagram_follow.php
    Warning: Invalid argument supplied for foreach() in /www/htdocs/********/instagram_follow.php on line 29

    This is because Instagram detected suspicious activity and needs you to reset your password. Make sure you change your $i count to under 40, $like_count to under 20 and CRON job to longer intervals between processes.

    posted by EXECUTOR brandon Friday, 19 May 2017 16:03 Comment Link
  • amirsyazi

    i got this message after putting the script to my hosting..

    File not found in Request.php on line 47

    wht does it mean

    posted by amirsyazi Tuesday, 30 May 2017 15:56 Comment Link
  • amirsyazi

    hi mr tan..try to email you but
    sending failed... Address not found
    Your message wasn't delivered to freeman@php8legs.com because the address couldn't be found. Check for typos or unnecessary spaces and try again.

    is this email add correct..?

    posted by amirsyazi Tuesday, 30 May 2017 21:55 Comment Link
  • amirsyazi

    hi mr tan..try to email you but
    sending failed... Address not found
    Your message wasn't delivered to freeman@php8legs.com because the address couldn't be found. Check for typos or unnecessary spaces and try again.

    is this email add correct..?

    posted by amirsyazi Tuesday, 30 May 2017 21:55 Comment Link
  • Lukas

    Hi. This is great code - i like it. Thank you for sharing and comments to this.

    The scripts looking for tags and return user id and media id for images he found by tags.
    I just thinking how it will be look url request/function to get recent media (last three for example) for specific user id. Then i could like them using already your function.
    In script you used some url request. They are a little different than those presented on official api site for Instangram. This is the part i don't understand why...
    Can you suggest something or help in that case? From where you know how the query should be?:)
    Sorry for disturb i am not profesional programmer. Just have some knowledge to write php simple scripts.

    posted by Lukas Friday, 09 June 2017 20:47 Comment Link
  • Goso.io

    How can I add my own proxy to the script? any ideas?

    posted by Goso.io Tuesday, 08 August 2017 15:34 Comment Link
  • Chin-Hock Tan

    Hello Goso.io ,
    You can place your proxy in curl code.

    posted by Chin-Hock Tan Saturday, 19 August 2017 08:39 Comment Link
  • Chin-Hock Tan

    Hello amirsyazi ,
    I moved this website to another server but forgot to create email account. Hope you have solved your problems.

    posted by Chin-Hock Tan Saturday, 19 August 2017 09:44 Comment Link
  • Ahmet

    Hello, I want to download this script. But I can't register this site. When I try to register, it says:

    Error
    The solution of task you submitted was incorrect. Please read the instruction and try again.

    posted by Ahmet Saturday, 26 August 2017 11:14 Comment Link
  • Chin-Hock Tan

    Hello Ahmet,
    Sorry for the problem. It has been fixed. You can register now. Thx

    posted by Chin-Hock Tan Sunday, 27 August 2017 01:49 Comment Link
  • Boss

    Nice Share Sir , free instagram followers

    posted by Boss Monday, 11 September 2017 07:48 Comment Link
  • JB

    Hi,

    I would like to add a class method to obtain general user data, like total posts, number of followers etc. It seems like the /user/{user-id} endpoint of the instagram API provides this information. How can I modify your codebase to obtain that info as well. I realise that his must be another cURL request.

    posted by JB Friday, 15 September 2017 15:11 Comment Link
  • med

    respecte its a really the best solution that i was searching over the web, please can you tell me how i can find instagram username by using the id ?

    posted by med Wednesday, 20 September 2017 14:03 Comment Link
  • med

    respecte its a really the best solution that i was searching over the web, please can you tell me how i can find instagram username by using the id ?

    posted by med Wednesday, 20 September 2017 14:03 Comment Link
  • ff

    Hey,

    nice idea.
    But could it be that this API is no linger supported by instagram?
    It seems that an oAuth login is required now.

    posted by ff Sunday, 01 October 2017 18:02 Comment Link
  • ff

    Hey,

    nice idea.
    But could it be that this API is no linger supported by instagram?
    It seems that an oAuth login is required now.

    posted by ff Sunday, 01 October 2017 18:02 Comment Link
  • yan

    hii admin please give me step by step how to use this. cause i dont understand to running this file.
    thank u so much

    best regards

    posted by yan Friday, 06 October 2017 09:05 Comment Link
  • yan

    hii admin please give me step by step how to use this. cause i dont understand to running this file.
    thank u so much

    best regards

    posted by yan Friday, 06 October 2017 09:06 Comment Link

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