andrewmd5 / InstagramUploader

Upload images to instagram without needing the app.
https://andrew.im/
MIT License
28 stars 8 forks source link

"message":"media_needs_reupload","error_title":"staged_position_not_found" #2

Open pk-pro opened 8 years ago

pk-pro commented 8 years ago

Hello! Thanks for the work! How this FIX?

ibasaw commented 8 years ago

+1

Shypes commented 8 years ago
function SendRequest($url, $post, $post_data, $user_agent, $cookies) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://i.instagram.com/api/v1/'.$url);
    curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    if($post) {
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
    }
    if ((version_compare(PHP_VERSION, '5.5') >= 0)) {
        curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
    } 
    if($cookies) {
        curl_setopt($ch, CURLOPT_COOKIEFILE,   dirname(__FILE__). '/cookies.txt');            
    } else {
        curl_setopt($ch, CURLOPT_COOKIEJAR,  dirname(__FILE__). '/cookies.txt');
    }
    $response = curl_exec($ch);
    $http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    return array($http, $response);
}

function GetPostData($filename)
{
    $path = getcwd() .'/uploads/' . $filename;
    if (!$path) {
        echo "The image doesn't exist " . $path;
    } else {
        $withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $filename);
        $convertImageToJpg = $this->ConvertImage($path, './uploads/' . 'converted_' . $withoutExt . '.jpg', 100);
        if ($convertImageToJpg) {
            $convertedPath =  getcwd() .'/uploads/' . 'converted_' . $withoutExt . '.jpg';
            $instagramPath =  getcwd() .'/uploads/' . 'instagram_' . $withoutExt . '.jpg';
            $this->SquareImage($convertedPath, $instagramPath);
            $post_data = array('device_timestamp' => time());
            if ((version_compare(PHP_VERSION, '5.5') >= 0)) {
                $post_data['photo'] = new CURLFile(realpath($instagramPath));
            } else {
                $aPost['photo'] = "@".realpath($instagramPath);
            }
            array_push($this->unlinkPaths, $convertedPath, $path, $instagramPath);
            return $post_data;
        }
    }
}

Issues with php version, replace the GetPostData and SendRequest method

andrewmd5 commented 8 years ago

@Shypes submit a pull request if this fixes the issue.

ibasaw commented 8 years ago

it work on a php page, but inside my website, i use a controller to execute the action, and got an error:

array(2)
[0]int200
[1]string(84)"{"status":"ok","errors":{"error":["Sorry, there was a problem with your request."]}}"

the action is call by an AJAX, maybe this is the cause

andrewmd5 commented 8 years ago

@ibasaw this code was originally designed for desktop usage, some changes need to be made to make it acceptable for web usage, specifically the way the cookie is grabbed. IF you look at SendRequest, the cookiejar is just saving the request to cookies.txt, this is a bit insecure and will disallow multiple request at once. It's possible the cookie is failing to be located on your page.

kiwina commented 8 years ago

change 'photo' => '@'.$filename to 'photo' => new CURLFile($filename) php 5.6+

ashrafhesham-92 commented 8 years ago

so, is there a solution for that error please ?

pk-pro commented 8 years ago

error disappeared when I changed hosting

ashrafhesham-92 commented 8 years ago

@pk-pro You mean that it can't be done from localhost ?

andrewmd5 commented 8 years ago

I wrote a c# version of this that is more secure and faster

https://github.com/Codeusa/InstaSharp

pk-pro commented 8 years ago

ashrafhesham-92 I do not know how about localhost, I did it in web hosting. Maybe it is due to IP adress...

EXECUTOR-brandon commented 8 years ago

mgp25 has a similar script that I use yet I also encounter the same media_needs_reupload / staged_position_not_found when I upload videos. I been posting on mgp25's GitHub trying to find a solution yet to find a solution. Some people suggest downgrade to 5.5.3 but that did not fix fyi. https://github.com/mgp25/Instagram-API/issues/191 https://github.com/mgp25/Instagram-API/issues/185

lasdou commented 8 years ago

The answer of kiwina is the solution of the error "staged_position_not_found" for who use a PHP version >= 5.6+

change 'photo' => '@'.$filename to 'photo' => new CURLFile($filename) php 5.6+

andreescocard commented 6 years ago

My code is with 'photo' => new CURLFile($filename) php 7.0 but showing this error, any ideas?

array(4) { ["message"]=> string(20) "media_needs_reupload" ["media"]=> array(1) { ["upload_id"]=> string(10) "XXXXXXX" } ["error_title"]=> string(34) "staged_position_not_found extra:{}" ["status"]=> string(2) "ok" }

Chmarusso commented 5 years ago

@andreescocard Same here. Instagram could change their API I guess. Have you solved this issue?

ThallesLazaro commented 5 years ago

Ainda nada né?!

Array

  | (   | [message] => media_needs_reupload   | [media] => Array   | (   | [upload_id] => 1544661292   | )   |     | [error_title] => staged_position_not_found extra:{}   | [status] => ok   | )

:(

luckydevilru commented 5 years ago

insta 😈 won!!!

neurolimitless commented 5 years ago

Have you solved it somehow?