function getCookie($userData) { $agent = GenerateUserAgent(); $guid = GenerateGuid(); $device_id = "android-" . $guid; $data = '{"device_id":"' . $device_id . '","guid":"' . $guid . '","username":"******","password":"******","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}'; $sig = GenerateSignature($data); $data = 'signed_body=' . $sig . '.' . urlencode($data) . '&ig_sig_key_version=4'; $response = SendRequest(array('url' => 'https://i.instagram.com/api/v1/accounts/login/', 'post' => $data, 'agent' => $agent, 'PATH_COOKIE' => $userData['PATH_COOKIE'])); $data = json_decode($response[1]); return array('status' => !empty($data) && $data->status == 'ok' ? 200 : 400, 'data' => $data); }
function postingImage($conf) { $image = GetPostData($conf['PATH_IMAGE']); $agent = GenerateUserAgent(); $dataUpload = SendRequest(array('url' => 'https://i.instagram.com/api/v1/media/upload/', 'post' => $image, 'agent' => $agent, 'useCookie' => true, 'PATH_COOKIE' => $conf['PATH_COOKIE'])); $response = json_decode($dataUpload[1]); if (empty($response) || $response->status != 'ok') { return $response = array('status' => $response->status, 'data' => $response); } $guid = GenerateGuid(); $device_id = "android-" . $guid; $requestData = '{"device_id":"' . $device_id . '","guid":"' . $guid . '","media_id":"' . $response->media_id . '","caption":"' . trim($conf['title']) . '","device_timestamp":"' . time() . '","source_type":"5","filter_type":"0","extra":"{}","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}'; $sig = GenerateSignature($requestData); $new_data = 'signed_body=' . $sig . '.' . urlencode($requestData) . '&ig_sig_key_version=4'; $response = SendRequest(['url' => 'https://i.instagram.com/api/v1/media/configure/', 'post' => $new_data, 'agent' => $agent, 'useCookie' => true, 'PATH_COOKIE' => $conf['PATH_COOKIE']]); $data = json_decode($response[1]); return array('status' => !empty($data) && $data->status == 'ok' ? 200 : 400, 'data' => $data); }
$post_data = array('device_timestamp' => time(), 'photo' => '@' . $filename); return $post_data; } } // Set the username and password of the account that you wish to post a photo to $username = '******'; $password = '******'; // Set the path to the file that you wish to post. // This must be jpeg format and it must be a perfect square $filename = './photo.jpg'; // Set the caption for the photo $caption = "Test Upload"; // Define the user agent $agent = 'Instagram 6.21.2 Android (19/4.4.2; 480dpi; 1152x1920; Meizu; MX4; mx4; mt6595; en_US)'; // Define the GuID $guid = GenerateGuid(); // Set the devide ID $device_id = "android-" . $guid; /* LOG IN */ // You must be logged in to the account that you wish to post a photo too // Set all of the parameters in the string, and then sign it with their API key using SHA-256 $data = '{"device_id":"' . $device_id . '","guid":"' . $guid . '","username":"******","password":"******","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}'; $sig = GenerateSignature($data); $data = 'signed_body=' . $sig . '.' . urlencode($data) . '&ig_sig_key_version=6'; $login = SendRequest('accounts/login/', true, $data, $agent, false); if (strpos($login[1], "Sorry, an error occurred while processing this request.")) { echo "Request failed, there's a chance that this proxy/ip is blocked"; } else { if (empty($login[1])) { echo "Empty response received from the server while trying to login"; } else {
function uploadImage($username, $password, $photo, $caption) { if (!isset($photo) || !is_file($photo)) { die("no photo found !"); } else { // $imageInfo = getimagesize($photo); // $width = $imageInfo["width"] ; // $height = $imageInfo["height"] ; list($width, $height) = getimagesize($photo); } // Set the caption for the photo // $caption = "wat"; // Define the user agent $agent = 'Instagram 7.10.0 Android (23/6.0; 515dpi; 1440x2416; huawei/google; Nexus 6P; angler; angler; en_US)'; // Define the GuID $guid = GenerateGuid(); // Set the devide ID $device_id = "android-" . $guid; /* LOG IN */ // You must be logged in to the account that you wish to post a photo too // Set all of the parameters in the string, and then sign it with their API key using SHA-256 $data = '{"device_id":"' . $device_id . '","guid":"' . $guid . '","username":"******","login_attempt_count":"1","password":"******","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}'; $sig = GenerateSignature($data); $data = 'signed_body=' . $sig . '.' . urlencode($data) . '&ig_sig_key_version=4'; $login = SendRequest('accounts/login/', true, $data, $agent, false); preg_match('#Set-Cookie: csrftoken=([^;]+)#', $login[2], $token); preg_match('#Set-Cookie: ds_user_id=([^;]+)#', $login[2], $id); $userid = $id[1]; if (strpos($login[1], "Sorry, an error occurred while processing this request.")) { echo "Request failed, there's a chance that this proxy/ip is blocked"; } else { if (empty($login[1])) { echo "Empty response received from the server while trying to login"; } else { // Decode the array that is returned $obj = @json_decode($login[1], true); if (empty($obj)) { echo "Could not decode the response: " . $body; } else { // Post the picture $boundary = $guid; $bodies = [['type' => 'form-data', 'name' => 'upload_id', 'data' => round(microtime(true) * 1000)], ['type' => 'form-data', 'name' => '_uuid', 'data' => $guid], ['type' => 'form-data', 'name' => '_csrftoken', 'data' => $token[1]], ['type' => 'form-data', 'name' => 'photo', 'data' => file_get_contents($photo), 'filename' => basename($photo), 'headers' => ['Content-type: application/octet-stream']]]; $data = buildBody($bodies, $boundary); $post = SendRequest('upload/photo/', true, $data, $agent, true, ['Proxy-Connection: keep-alive', 'Connection: keep-alive', 'Accept: */*', 'Content-type: multipart/form-data; boundary=' . $boundary, 'Accept-Language: en-en', 'Accept-Encoding: gzip, deflate']); preg_match('#Set-Cookie: csrftoken=([^;]+)#', $post[2], $token); if (empty($post[1])) { echo "Empty response received from the server while trying to post the image"; } else { // Decode the response $obj = @json_decode($post[1], true); if (empty($obj)) { echo "Could not decode the response"; } else { $status = $obj['status']; if ($status == 'ok') { // Remove and line breaks from the caption $caption = preg_replace("/\r|\n/", "", $caption); $media_id = $obj['upload_id']; // Now, configure the photo $data = array('caption' => $caption, 'upload_id' => $media_id, 'source_type' => 3, 'edits' => array('crop_zoom' => 1.0, 'crop_center' => array(0.0, -0.0), 'crop_original_size' => array($width, $height), 'black_pixels_ratio' => 0), 'device' => array('manufacturer' => 'asus', 'model' => 'Nexus 7', 'android_version' => 22, 'android_release' => '5.1'), '_csrftoken' => $token[1], '_uuid' => $guid, '_uid' => $userid); $sig = GenerateSignature(json_encode($data)); $new_data = 'signed_body=' . $sig . '.' . urlencode(json_encode($data)) . '&ig_sig_key_version=4'; $conf = SendRequest('media/configure/', true, $new_data, $agent, true); if (empty($conf[1])) { echo "Empty response received from the server while trying to configure the image"; } else { if (strpos($conf[1], "login_required")) { echo "You are not logged in. There's a chance that the account is banned"; } else { $obj = @json_decode($conf[1], true); $status = $obj['status']; if ($status != 'fail') { echo "Success"; } else { echo 'Fail'; echo var_dump($obj); } } } } else { echo "Status isn't okay"; echo var_dump($obj); } } } } } } }