2014-06-15 124 views
0

我想使用API​​登录instagram。但我得到的错误:php instagram api登录错误

{"status":"fail","message":"Your version of Instagram is out of date. Please upgrade your app to log in to Instagram."} 

而且我的PHP代码:

function open($url,$post="") { 
$cookies = 'cookies.txt'; 
     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL, $url); 
     curl_setopt($ch, CURLOPT_HEADER, 0); 
     if ($post != "") { 
       curl_setopt($ch, CURLOPT_POST,1); 
       curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
     } 

     curl_setopt($ch, CURLOPT_USERAGENT, 'Instagram'); 
     curl_setopt($ch,CURLOPT_TIMEOUT, 50); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch,CURLOPT_REFERER, ""); 
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 

     curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookies); 
     curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookies); 

     $data = curl_exec($ch); 
     curl_close($ch); 
     return $data; 
} 

    function _render_form($data) { 
     $t = ""; 
     foreach ($data as $k=>$v) { $t .= "&$k=$v";} 
     return str_replace("###&","","###".$t); 
    } 

function login($username, $password) { 
      $post = _render_form(array("username" => $username, "password" => $password, "device_id" => "MY_DEVICE_ID")); 
      $isi = open("https://instagram.com/api/v1/accounts/login/", $post); 
      echo $isi; die; 
    } 
$login = login('MY_USERNAME', 'MY_PASSWORD'); 

我改变了设备ID到我的手机的设备ID。但问题没有解决......任何想法?

+0

我的猜测是你正在使用API​​的过时形式。检查_current_ API文档并确保您的代码符合它。 –

回答

0

Instagram不再支持使用用户名和密码登录。相反,您应该use oAuth执行需要验证的请求。

使用像this one这样的库比手动实现这个要容易得多。