Answer the question
In order to leave comments, you need to log in
Is there a problem with the autofollowing script on Instagram?
A couple of days ago the code worked, but now it gives an error. Apparently, in the searchUserByUsername function:
<?php
set_time_limit(0);
class Instagram {
public $user;
private $signatureKey;
public $is_logged = false;
public static $apiURL = '//i.instagram.com/api/v1/';
public static $userAgent = 'Instagram 6.9.1 Android (15/4.0.4; 160dpi; 320x480; Sony; MiniPro; mango; semc; en_Us)';
public static $key_ver = 4;
public function __construct($login, $password, $key) {
$this->user = ['username'=>$login, 'password'=>$password];
$this->signatureKey = $key;
$this->GUID = $this->GenerateGuid();
$this->curl = new cUrl($this->user['username'], self::$userAgent);
$this->Auth();
return true;
}
private function Auth() {
$this->inLog("Auth");
$login = $this->makeApiCall('accounts/login/', $this->user, true, false);
if(isset($login['status']) && $login['status'] == 'ok') {
$this->inLog("Login success..\nLogged in as ".$login['logged_in_user']['username']); //todo msgs in array
$this->is_logged = true;
$this->user = $login['logged_in_user'];
} else die($this->inLog('Wrong username/password'));
}
public function searchUserByUsername($username) {
$this->inLog("searchUserByUsername ".$username);
$req = $this->makeApiCall('users/search/?query='.$username)['users'][0];
if(!isset($req['pk'])) {
throw new Exception("User nor found", 1);
return false;
}
return $req;
}
public function Follow($uid, $destroy = false) {
$request = $this->makeApiCall('friendships/'.($destroy ? 'destroy/' :'create/').$uid.'/', ['user_id'=>$uid]);
return $request;
}
public function makeApiCall($method, $params = [], $ssl = false, $use_cookie = true) {
$defaultRequestBody = [
"device_id"=>'android-'.$this->GUID,
"guid"=>$this->GUID,
"Content-Type"=>"application/x-www-form-urlencoded; charset=UTF-8"
];
if(!empty($params)) {
$params = json_encode(array_merge($defaultRequestBody, $params));
$signedBody = 'signed_body='.$this->generateSig($params).".".urlencode($params).'&ig_sig_key_version='.self::$key_ver;
}
return json_decode($this->curl->call(($ssl ? 'https:' : 'http:').self::$apiURL.$method, $signedBody, $use_cookie), true);
}
}
Answer the question
In order to leave comments, you need to log in
What a thought. In your code and in the code (the link was above) there is a different call to Api. Apparently now you need to use the key. If I succeed, I'll write
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question