Пару дней назад код работал, но теперь выдает ошибку. Видимо, в функции searchUserByUsername:
<?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);
}
}
В чем проблема?
P.S. Тостер не дал загрузить весь код. Оставил основные функции (на мой взгляд).