如何使用API​​将图片发布到instagram

我正在构build一个PHP应用程序,需要将用户上传的图片直接发布到Instagram,但经过快速search,我发现在API中没有这样的function:(而且感觉很奇怪…因为他们应该提供一个。我不确定是否有任何其他的方式(Android和iOS的应用程序除外)上传图片使用PHP。请给我任何forms的想法,如果有任何可能性。

我也读过这个,

如何使用PHP与Instagram分享链接和照片

谢谢

如果你阅读你分享的链接,接受的答案是:

你不能通过API发布图片到Instagram。

看来你可以在PC上模拟Instagram。

Bluestacks是一个模拟器,可让您在PC / Mac上运行android应用程序

我不确定它的工作效果如何。

第二个select是使用这个 。 这是Instagram的API,但它被颠倒过来,解释如何使用它(包括上传媒体)。

再次,不知道这有多好。

更新:

Instagram现在禁止帐户和基于这种方法删除图像。 请谨慎使用。


似乎所有用这个问题回答这个问题的人都是it can't be done正确的。 正式的,你不能用Instagram的照片发布到Instagram的照片。 但是,如果您对API进行反向工程,则可以。

 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); if($post) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); } if($cookies) { curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt'); } else { curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt'); } $response = curl_exec($ch); $http = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return array($http, $response); } 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)); } function GenerateUserAgent() { $resolutions = array('720x1280', '320x480', '480x800', '1024x768', '1280x720', '768x1024', '480x320'); $versions = array('GT-N7000', 'SM-N9000', 'GT-I9220', 'GT-I9100'); $dpis = array('120', '160', '320', '240'); $ver = $versions[array_rand($versions)]; $dpi = $dpis[array_rand($dpis)]; $res = $resolutions[array_rand($resolutions)]; return 'Instagram 4.'.mt_rand(1,2).'.'.mt_rand(0,2).' Android ('.mt_rand(10,11).'/'.mt_rand(1,3).'.'.mt_rand(3,5).'.'.mt_rand(0,5).'; '.$dpi.'; '.$res.'; samsung; '.$ver.'; '.$ver.'; smdkc210; en_US)'; } function GenerateSignature($data) { return hash_hmac('sha256', $data, 'b4a23f5e39b5929e0666ac5de94c89d1618a2916'); } function GetPostData($filename) { if(!$filename) { echo "The image doesn't exist ".$filename; } else { $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 = 'ig_username'; $password = 'ig_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 = 'pictures/test.jpg'; // Set the caption for the photo $caption = "Test caption"; // Define the user agent $agent = GenerateUserAgent(); // 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":"'.$username.'","password":"'.$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); 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 $data = GetPostData($filename); $post = SendRequest('media/upload/', true, $data, $agent, true); 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['media_id']; $device_id = "android-".$guid; $data = '{"device_id":"'.$device_id.'","guid":"'.$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 = GenerateSignature($data); $new_data = 'signed_body='.$sig.'.'.urlencode($data).'&ig_sig_key_version=4'; // Now, configure the photo $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'; } } } } else { echo "Status isn't okay"; } } } } } } 

只需将上面的代码复制并粘贴到文本编辑器中,相应地更改一些variables,然后VOILA! 我写了一篇关于这个的文章 ,而且我做了很多次。 在这里看到一个演示。

您可以使用pynstagram ,它是简单的CLI工具和Python模块:

pynstagram -u username -p password -f ~/kittens/31415.jpg -t '#meow'

对于发现此问题的用户,您可以使用iPhone挂钩将照片传递到iPhone上的Instagram共享stream程(从应用程序到滤镜屏幕): http : //help.instagram.com/355896521173347除此之外,目前还没有在API的版本1的方式。