[英]php instagram login error
直到上周,我才能使用此代码登录 instagram。 但现在不工作了。 也许“ http://instagram.com/accounts/login/ajax ”不工作我必须做什么才能工作顺利?
<?php
class Instagram {
public $data;
public function saveCache($users) {
$opt_keys = array();
foreach ($users as $key => $user) {
$ROOT_PATH[$key] = dirname(__FILE__) . "/cookies/". $user["username"];
if (!(is_dir($ROOT_PATH[$key]))) {
mkdir($ROOT_PATH[$key]);
}
$cookie_filename = $ROOT_PATH[$key] . "/" . $user["username"] . "-cache.txt";
$this->data[$key] = array("cookie_filename" => $cookie_filename, "state" => "get_cookie", "username" => $user["username"], "password" => $user["password"]);
$opts[$key] = array("url" => "https://www.instagram.com/accounts/login/?force_classic_login", "cookie_jar" => $cookie_filename);
}
multi_curl($opts, function ($que, $key) use ($ROOT_PATH) {
$content = $que->content;
$opt_key =& $this->data[$key];
$username = $opt_key["username"];
$password = $opt_key["password"];
$cookie_filename = $opt_key["cookie_filename"];
$state =& $opt_key["state"];
switch ($state) {
case "get_cookie":
if (preg_match("#\"csrf_token\":\"([a-zA-Z0-9]{0,}+)\"#siU", $content, $match)) {
$csrf_token = array_pop($match);
$post_string = array("username" => trim($username), "password" => trim($password));
$post_string = http_build_query($post_string, "", "&");
$state = "login";
return array("url" => "https://instagram.com/accounts/login/ajax/", "post" => $post_string, "cookie_jar" => $cookie_filename, "cookie_file" => $cookie_filename, "key" => $key, "http_header" => array("Origin:https://instagram.com", "Referer:https://instagram.com/accounts/login/ajax/?targetO1rigin=https%3A%2F%2Finstagram.com", "X-CSRFToken:" . $csrf_token, "X-Instagram-AJAX: 1", "X-Requested-With: XMLHttpRequest"));
}
break;
case "login":
$json = json_decode($content, false);
if (isset($json->authenticated) && $json->authenticated) {
echo($username . " giri\xc5\x9f yap\xc4\xb1ld\xc4\xb1<br>");
$tokens = $json->authenticated;
$dosya_adi = "userler.txt";
$dosya = fopen ($dosya_adi , 'a+') or die ("Dosya açılamadı!");
fwrite ( $dosya , "$username:$password\n" ) ;
fclose ($dosya);
$state = "insta_main";
return array("url" => "https://instagram.com/web/likes/1009482544587251742/like/", "cookie_file" => $cookie_filename, "key" => $key, "http_header" => array("Referer:https://instagram.com/", "X-CSRFToken:" . @$csrf_token, "X-Instagram-AJAX:1", "X-Requested-With:XMLHttpRequest"));
}
echo($username . " giri\xc5\x9f yap\xc4\xb1lamad\xc4\xb1.<br>");
@unlink($opt_key["cookie_filename"]);
@rmdir($ROOT_PATH[$key]);
break;
case "insta_main":
break;
default:
break;
}
}
, 150);
}
}
require("Curl.php");
define("ROOT_PATH", dirname(__FILE__));
set_time_limit(0);
header('Content-Type: text/html; charset=utf-8');
ini_set("display_errors", 1);
ini_set("error_log", dirname(__FILE__) . "/php-error.log");
$instagram = new Instagram();
if ($_POST) {
$users = explode("\n", $_POST["users"]);
$veruser = array();
foreach ($users as $user) {
$bol = explode(":", $user);
$veruser[] = array("username" => trim($bol[0]), "password" => trim($bol[1]));
}
$instagram->saveCache($veruser);
exit();
}
echo("<form action=\"\" method=\"POST\">\r\n <textarea name=\"users\" rows=\"20\" cols=\"50\"></textarea>\r\n <input type=\"submit\">\r\n</form>\r\n");
function delTree($dir) {
$files = array_diff(scandir($dir), array('.','..'));
foreach ($files as $file) {
(is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
}
return rmdir($dir);
}
试试这个解决方案,我测试它并且它有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.