Answer the question
In order to leave comments, you need to log in
Instagram authorization without API?
Good afternoon. Due to the fact that instagram now gives permissions to post and delete in its api only by a verified application, the question arose - how to work with it now?
Questions arose even at the login stage. I can't figure out how to login. All that comes to mind is to use something like Phantomjs and just fill/click on the required fields and work with the result. But what if you have to work not with one user, but with several (within the same application)?
Who has thoughts - tell me, please. The authorization code would also be very interesting.
Answer the question
In order to leave comments, you need to log in
You send a post request like username=NAME&password=PASSWORD to https://instagram.com/accounts/login/ajax/ and save cookies. With these cookies you walk around the site.
function curl_file($url, $cookie = 'coockie', $post = '', $xhr = '') {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
if ($post) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
if ($xhr) {
preg_match('|csrftoken(.*)|', file_get_contents('coockie'), $csrf);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-CSRFToken:' . trim($csrf[1]), 'X-Instagram-AJAX:1', 'X-Requested-With:XMLHttpRequest'));
}
$file = curl_exec($ch);
curl_close($ch);
return $file;
}
curl_file('https://instagram.com/accounts/login/ajax/', 'coockie', 'username=Имя&password=Пароль', 1);
echo curl_file('https://instagram.com/', 'coockie', 0, 1); //Выйдет твоя страничка
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question