繁体   English   中英

PHP的Instagram的API登录错误

[英]php instagram api login error

我想使用API​​登录instagram。 但是我得到了错误:

{"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。 但是问题没有解决……有什么想法吗?

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

使用图书馆像这一次会比手动执行这一容易得多。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM