D
D
Deterrent2017-06-21 15:31:34
PHP
Deterrent, 2017-06-21 15:31:34

Authorization in instagram through curl, what's next?

I'm trying to do so.

<?php
ini_set('display_errors', TRUE); error_reporting(E_ALL);

$login_url = 'https://www.instagram.com/';
$login_url_post = 'https://www.instagram.com/accounts/login/ajax/';

$agent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0";
$post_data = 'username=user&password=pass';

$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_URL, $login_url );
//curl_setopt($ch, CURLOPT_POST, 1 );
//curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, '/home/deterrent/www/site.ru/curl/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/home/deterrent/www/site.ru/curl/cookie.txt');

$postResult = curl_exec($ch);

var_dump ($postResult);

$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_USERAGENT, $agent);
curl_setopt($ch2, CURLOPT_URL, $login_url_post );
curl_setopt($ch2, CURLOPT_POST, 1 );
curl_setopt($ch2, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, 1);
//curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch2, CURLOPT_COOKIEJAR, '/home/deterrent/www/site.ru/curl/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/home/deterrent/www/site.ru/curl/cookie.txt');

$postResult2 = curl_exec($ch2);

var_dump ($postResult2);
?>

But I get an Instagram page that says
"This page could not be loaded. If you have cookies disabled in your browser, or you are browsing in Private Mode, please try enabling cookies or turning off Private Mode, and then retrying your action."
Cookies are written to a file. If you look at the browser. then the username and password are transmitted to https://www.instagram.com/accounts/login/ajax/ , and the cookies received, it seems, should also be sent. Tell me what I missed, where there may be an error.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question