📜 ⬆️ ⬇️

We write instagram-robot, put likes by tags

Sometimes, for the sake of warm-up, I set myself tasks. Just for fun. Most often, they are forgotten immediately after the found solution and are no longer used. It happened this time. I read on the Internet that an effective way to promote on Instagram is to search for photos by tags and the likes of them. If you choose the right tags (usually those that correspond to the subject of your account), you will receive not only reply likes, but also new subscribers (which was confirmed).

Task


Write a robot (MySQl + php + js), which would find photos by tags and put them likes. Moreover, it is desirable that our robot does not hit the ban.

Authorization


First of all, we need to log in. Therefore, the main page of the robot has only one button link.
<a href="https://api.instagram.com/oauth/authorize/?client_id=_id&redirect_uri=_____&response_type=code&scope=basic+comments+relationships+likes"><img src="img/logo.png"></a> 

and at the very beginning we check if the visitor has not already authorized us (we check the cookie), and if so, we redirect to the personal account.
 if ($_COOKIE['sess_id']!="") header('location:    '); 


Below is the contents of the script, a person gets here after giving us permission to process his data. The file included at the beginning of the config.php establishes a connection to the database
')
 //    include 'config.php'; //    ,      if ($_GET['error']=='access_denied') header('location: ___'); else { if ($_GET['code']!="") { //  $ClientID = '__'; $ClientSecret = '__'; $uri = '___'; $url = "https://api.instagram.com/oauth/access_token"; $access_token_parameters = array( 'client_id' => $ClientID, 'client_secret' => $ClientSecret, 'grant_type' => 'authorization_code', 'redirect_uri' => $uri, 'code' => $_GET['code'] ); $curl = curl_init($url); curl_setopt($curl,CURLOPT_POST,true); curl_setopt($curl,CURLOPT_POSTFIELDS,$access_token_parameters); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($curl); curl_close($curl); $data = json_decode($data, true); $token = $data['access_token']; $full_name = $data['user']['full_name']; $username = $data['user']['username']; $profile_picture = $data['user']['profile_picture']; $id = $data['user']['id']; if ($id!="") { //  ? $nashelsy = 0; $sql = mysql_query("SELECT*FROM qf_users Where qf_id='".$id."' LIMIT 1"); while($record = mysql_fetch_array($sql)) $nashelsy = 1; // id  $sess_id = md5(md5($id).$_SERVER['REMOTE_ADDR']); if ($nashelsy==0) { // ,  $sql = mysql_query("INSERT INTO `qf_users` (`qf_id`, `qf_token`, `qf_username`, `qf_full_name`, `qf_profile_picture`, `qf_sess_id`, `qf_ip`) VALUES ('".$id."', '".$token."', '".$username."', '".$full_name."', '".$profile_picture."', '".$sess_id."', '".$_SERVER['REMOTE_ADDR']."');"); } else { // ,  $sql1 = mysql_query("UPDATE `qf_users` SET `qf_token` = '".$token."', `qf_username` = '".$username."', `qf_full_name` = '".$full_name."', `qf_profile_picture` = '".$profile_picture."', `qf_ip` = '".$_SERVER['REMOTE_ADDR']."', `qf_sess_id` = '".$sess_id."' WHERE `qf_users`.`qf_id` = '".$id."' LIMIT 1 ;"); } //       ,           setcookie('sess_id',$sess_id,time()+86400,'/','_'); header('location: __'); } } } 


Go to the personal account



We check to see if we have such a user, and if not, send it to the main one.
 include 'config.php'; $sql = mysql_query("SELECT*FROM qf_users WHERE qf_sess_id='".$_COOKIE['sess_id']."'"); while($record = mysql_fetch_array($sql)) { $user_id = $record['qf_id']; $user_token = $record['qf_token']; $user_email = $record['qf_email']; $user_username = $record['qf_username']; $user_full_name = $record['qf_full_name']; $user_profile_picture = $record['qf_profile_picture']; $user_ip = $record['qf_ip']; } if (md5(md5($user_id).$_SERVER['REMOTE_ADDR'])!=$_COOKIE['sess_id']) { setcookie('sess_id',$_COOKIE['sess_id'],time()-3600,'/',''); header('location:   '); } 


A rather primitive authorization, but it was immediately assumed that no one would use the service except me, so there should be no problems.

On the very page we will place only a few fields: to enter a tag, to enter the maximum number of likes in a photo (photos with a large number will not be liked, because it does not make sense, the “Go” button and the “Exit” button) "). We also need a field where we will save the id of the next photo.
 <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="left" valign="bottom">     <input name="tag" id="tag" type="text" placeholder=' '>     <input name="kollikes" id="kollikes" type="number" value="40"> <span style="display:inline-block; border:1px solid black; padding:5px; cursor:pointer" onClick="gogogo()" id="bb">!</span> <hr> <input name="last_id" id="last_id" type="text" placeholder=''> </td> <td align="right" valign="bottom"> <img src="" height="30"> <?=$user_full_name?> / <a href="logout.php"></a></td> </tr> </table> 


and don't forget to watch for what is happening
 <div id="res" align="center"></div> 


Further, the logic is simple, we need to imitate the behavior of an ordinary person, otherwise our robot will be quickly forgotten, and all the work is frightened. Therefore, we add the following code to the page (all timeouts can be chosen arbitrarily):
 <script> var rep = 0; setInterval(function() { if (rep==1) gogogo(); },3000); function gogogo() { rep = 0; $('#res').text('...   ...'); $('#bb').text('...'); $.post('getphoto.php',{token:'<?=$user_token?>',tag:tag.value,kollikes:kollikes.value,last_id:last_id.value}, function (data) { arr = data.split('(@-a4h-@)'); $('#title').text(arr[0]); $('#mylink').attr('href',arr[1]); $('#myimg').attr('src',arr[2]); myid.value = arr[3]; last_id.value=arr[4]; $('#bb').text('like'); $('#res').text('...   ...'); setTimeout(function() { $.post('like.php',{id:myid.value,token:'<?=$user_token?>'}, function (data) { arr = data.split('<-=a4h=->'); $('#res').html(arr[0]+"<br>"+arr[1]); if (arr[0]==200) rep=1; }); }, Math.floor(Math.random() * (6000 - 3000) + 3000)); }); } </script> 


It remains to see what happens in the scripts that are looking for photos and put huskies.

Search for photos by tags


This script forms a string with a separator, which will be passed to us and parsed.
 $user_token = $_POST['token']; $images = 0; $title = ''; $src = ''; $link = ''; $like = 0; $im_id = ''; $last_id = $_POST['last_id']; while ($images==0) { if ($last_id!="") $api = 'https://api.instagram.com/v1/tags/'.$_POST['tag'].'/media/recent?max_tag_id='.$last_id.'&count=1&access_token='.$user_token; else $api = 'https://api.instagram.com/v1/tags/'.$_POST['tag'].'/media/recent?count=1&access_token='.$user_token; $response = file_get_contents($api); $last_id = htmlspecialchars(json_decode($response)->pagination->next_max_tag_id); foreach(json_decode($response)->data as $item){ $title = $item->caption->text; $src = $item->images->low_resolution->url; $link = $item->link; $like = $item->likes->count; $im_id = $item->id; if ($like < $_POST['kollikes']) { $images = 1; echo htmlspecialchars($title)."(@-a4h-@)".htmlspecialchars($link)."(@-a4h-@)".htmlspecialchars($src)."(@-a4h-@)".htmlspecialchars($im_id)."(@-a4h-@)".$last_id; } } } 


Put the likes


It's still easier here.
 <?php $id = $_POST['id']; $user_token = $_POST['token']; $url = "https://api.instagram.com/v1/media/".$id."/likes"; $access_token_parameters = array( 'access_token' => $user_token ); $curl = curl_init($url); curl_setopt($curl,CURLOPT_POST,true); curl_setopt($curl,CURLOPT_POSTFIELDS,$access_token_parameters); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($curl); curl_close($curl); $data = json_decode($data, true); $result = $data['meta']['code']; $result2 = $data['meta']['error_message']; echo $result."<-=a4h=->".$result2; ?> 


Profit


The code is not perfect, assembled on the knee, the main idea was to show how to imitate the behavior of a living person so as not to fall under sanctions.
Demo

Source: https://habr.com/ru/post/200472/


All Articles