Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include 'instagram.class.php';
- $instaUsername = "xxxxx";
- $instaPassword = "xxxxx";
- $folderLocation = "upload";
- $attempts = 0;
- $loginSucces = false;
- $postImageSucces = false;
- $maxAttempts = 25;
- // --------------------------------------------------------------------------------------------------------
- $captionOptions = ['caption 1', 'caption 2', 'caption 3', 'caption 4', 'caption 5'];
- $caption = $captionOptions[array_rand($captionOptions)];
- // --------------------------------------------------------------------------------------------------------
- $files = glob($folderLocation.'/*.{jpg,png,gif,jpeg}', GLOB_BRACE);
- array_multisort(array_map('filemtime', $files), SORT_NUMERIC, SORT_DESC, $files);
- if(empty($files)) {
- exit("No pictures found");
- }
- $fullFileLocation = $files[0];
- $fileNameWithExtension = explode('/', $fullFileLocation)[1];
- $fileName = explode('.', $fileNameWithExtension)[0];
- $fileExtension = explode('.', $fileNameWithExtension)[1];
- if(file_exists("$folderLocation/{$fileName}.txt")) {
- $caption = file_get_contents("$folderLocation/{$fileName}.txt");
- }
- // --------------------------------------------------------------------------------------------------------
- // login & upload
- $instaGram = new Instagram();
- do {
- if($attempts >= 15) {
- exit("15 times... error? ??");
- }
- if($loginSucces == false) {
- $response = $instaGram->Login($instaUsername, $instaPassword);
- if(strpos($response[1], "Sorry") || empty($response[1])) {
- // proxy fails, get a new one
- $instaGram->delProxy();
- } else {
- $loginSucces = true;
- sleep(5);
- }
- }
- if($loginSucces == true) {
- if($instaGram->Post($fullFileLocation, $caption)) {
- $postImageSucces = true;
- }
- }
- $attempts++;
- } while($postImageSucces == false);
- // --------------------------------------------------------------------------------------------------------
- // logn/upload succes
- // --------------------------------------------------------------------------------------------------------
- // rename files
- rename("{$fullFileLocation}", "./gebruikt/{$fileNameWithExtension}");
- // caption txt bestand
- if(file_exists("$folderLocation/{$fileName}.txt")) {
- rename("{$folderLocation}/{$fileName}.txt", "./gebruikt/{$fileName}.txt");
- }
- // --------------------------------------------------------------------------------------------------------
- <?php
- Class Instagram
- {
- public $username;
- public $password;
- private $guid;
- private $userAgent = 'Instagram 6.21.2 Android (19/4.4.2; 480dpi; 1152x1920; Meizu; MX4; mx4; mt6595; nl_BE)';
- private $instaSignature ='xxxxxxxxxxxxx';
- private $instagramUrl = 'https://i.instagram.com/api/v1/';
- function __construct() {
- if (!extension_loaded('curl')) trigger_error('php_curl extension is not loaded', E_USER_ERROR);
- }
- function __destruct() {
- }
- private function writeProxy($ip) {
- file_put_contents("./upload/proxy.txt", $ip);
- }
- public function delProxy() {
- file_put_contents("./upload/proxy.txt", "");
- }
- private function getProxyFromFile() {
- return file_get_contents("./upload/proxy.txt");
- }
- private function getProxy() {
- $proxy = file_get_contents("./upload/proxy.txt");
- if(empty($proxy)) {
- $data = json_decode(file_get_contents('http://gimmeproxy.com/api/getProxy?country=NL&supportsHttps=true&maxCheckPeriod=15000&minSpeed=250'));
- $proxy = trim($data->ipPort);
- $this->writeProxy($proxy);
- } else {
- $proxy = $proxy;
- }
- return $proxy;
- }
- private function Request($url, $post, $post_data, $cookies) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $this->instagramUrl . $url);
- curl_setopt($ch, CURLOPT_PROXY, $this->getProxy());
- curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
- //curl_setopt($ch, CURLOPT_HEADER, 1);
- if($post) {
- curl_setopt($ch, CURLOPT_POST, 1);
- if ((version_compare(PHP_VERSION, '5.5') >= 0)) {
- curl_setopt($ch, CURLOPT_SAFE_UPLOAD, 1);
- }
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
- }
- if($cookies) {
- curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__). '/upload/cookies.txt');
- } else {
- curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__). '/upload/cookies.txt');
- }
- $response = curl_exec($ch);
- $http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- curl_close($ch);
- return array($http, $response);
- }
- private function GenerateGuid() {
- return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
- mt_rand(0, 65535),
- mt_rand(0, 65535),
- mt_rand(0, 65535),
- mt_rand(16384, 20479),
- mt_rand(32768, 49151),
- mt_rand(0, 65535),
- mt_rand(0, 65535),
- mt_rand(0, 65535));
- }
- private function GenerateSignature($data) {
- return hash_hmac('sha256', $data, $this->instaSignature);
- }
- private function GetPostData($path) {
- $post_data = array('device_timestamp' => time());
- if ((version_compare(PHP_VERSION, '5.5') >= 0)) {
- $post_data['photo'] = new CURLFile(realpath($path));
- } else {
- $post_data['photo'] = "@".realpath($path);
- }
- return $post_data;
- }
- 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';
- return $this->Request('accounts/login/', true, $data, false);
- }
- private function PostImage($photo) {
- $data = $this->GetPostData($photo);
- return $this->Request('media/upload/', true, $data, true);
- }
- private function PostCaption($caption, $media_id) {
- $caption = preg_replace("/r|n/", "", $caption);
- $device_id = "android-".$this->guid;
- $data = '{"device_id":"'.$device_id.'","guid":"'. $this->guid .'","media_id":"'.$media_id.'","caption":"'.trim($caption).'","device_timestamp":"'.time().'","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/configure/', true, $new_data, true);
- }
- public function Post($photo, $caption){
- $response = $this->PostImage($photo);
- // print_r($response);
- if(empty($response[1])) {
- return false;
- }
- $obj = @json_decode($response[1], true);
- $status = $obj['status'];
- if($status == 'ok') {
- // Remove and line breaks from the caption
- $media_id = $obj['media_id'];
- $response = $this->PostCaption($caption, $media_id);
- return true;
- }
- return false;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment