我尝试使用 PHP 中的 instagramm oauth,首先我打开 oauth 页面,获取 cookie(csrfmiddlewaretoken abnd mid)并在页面中解析 csrfmiddlewaretoken 隐藏,然后在https://instagram.com/上使用我的用户名和密码发送它帐户/登录/,但我收到 304 错误。为什么?`
<?
require_once 'inc.php';
$redirect_uri = "http://178.132.206.91/?viewer_id=".$_GET['viewer_id']."&auth_key=".$_GET['auth_key];
$link="https://instagram.com/oauth/authorize/?client_id=".INST_CLIENT."&redirect_uri=".$redirect_uri."&response_type=token";
// $page=file_get_contents($link);
$ch = curl_init();
//Указываем URL, куда будем обращаться. Протокол https://
curl_setopt($ch, CURLOPT_URL, $link);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);
$page = curl_exec($ch);
curl_getinfo ( $ch );
$header = substr($page,0,curl_getinfo($ch,CURLINFO_HEADER_SIZE));
$body = substr($page,curl_getinfo($ch,CURLINFO_HEADER_SIZE));
preg_match_all("/Set-Cookie: (.*?)=(.*?);/i",$header,$res);
$cookie[$res[1][1]] = $res[2][1];
$cookie[$res[1][2]] = $res[2][2];
$cookies = http_build_query($cookie, '', ';');
echo $page;
//echo $cookies;
curl_close($ch);
//echo $header;
preg_match('#<input\s+type="hidden"\s+name="csrfmiddlewaretoken"\s+value="(.+?)".+?/>#si', $page, $match);
$data['csrfmiddlewaretoken'] = $match[1];
$data['username'] = "040819";
$data['password'] = "040819";
$datas = http_build_query($data, '', ';');
$ch = curl_init();
$authlink = "https://instagram.com/accounts/login/";
curl_setopt($ch, CURLOPT_URL, $authlink);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);
curl_setopt ($ch, CURLOPT_COOKIE, $cookies);
print_r($cookies);
curl_setopt($ch, CURLOPT_POSTFIELDS, $datas);
$page = curl_exec($ch);
curl_getinfo($ch);
$header = substr($page,0,curl_getinfo($ch,CURLINFO_HEADER_SIZE));
$body = substr($page,curl_getinfo($ch,CURLINFO_HEADER_SIZE));
echo $page;
echo $csr;
?>`