InstagramUploader icon indicating copy to clipboard operation
InstagramUploader copied to clipboard

"message":"media_needs_reupload","error_title":"staged_position_not_found"

Open pk-pro opened this issue 9 years ago • 18 comments

Hello! Thanks for the work! How this FIX?

pk-pro avatar Mar 28 '16 08:03 pk-pro

+1

ibasaw avatar Apr 11 '16 13:04 ibasaw

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

Shypes avatar Apr 13 '16 11:04 Shypes

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

andrewmd5 avatar Apr 13 '16 15:04 andrewmd5

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

ibasaw avatar Apr 13 '16 16:04 ibasaw

@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.

andrewmd5 avatar Apr 13 '16 17:04 andrewmd5

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

kiwina avatar Apr 30 '16 12:04 kiwina

so, is there a solution for that error please ?

ashrafhesham-92 avatar May 08 '16 12:05 ashrafhesham-92

error disappeared when I changed hosting

pk-pro avatar May 11 '16 06:05 pk-pro

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

ashrafhesham-92 avatar May 11 '16 07:05 ashrafhesham-92

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

https://github.com/Codeusa/InstaSharp

andrewmd5 avatar May 11 '16 16:05 andrewmd5

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

pk-pro avatar May 12 '16 06:05 pk-pro

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

EXECUTOR-brandon avatar Jun 08 '16 18:06 EXECUTOR-brandon

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+

lasdou avatar Oct 11 '16 07:10 lasdou

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" }

andreescocard avatar Oct 22 '18 13:10 andreescocard

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

Chmarusso avatar Nov 28 '18 13:11 Chmarusso

Ainda nada né?!

Array

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

:(

ThallesLazaro avatar Dec 13 '18 00:12 ThallesLazaro

insta 😈 won!!!

luckydevilru avatar Apr 27 '19 15:04 luckydevilru

Have you solved it somehow?

neurolimitless avatar Sep 24 '19 07:09 neurolimitless