5

I try to login on Instagram without using API. When I logged I am opening someone's profile but the page refreshes all the time. The remaining part of the script works great. That's the script:

<?php

$c = curl_init();
    curl_setopt($c, CURLOPT_URL, 'https://instagram.com/accounts/login/?force_classic_login');
    curl_setopt($c, CURLOPT_REFERER, 'https://instagram.com/accounts/login/?force_classic_login');
    curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($c, CURLOPT_COOKIEFILE, 'cookiess.txt');
    curl_setopt($c, CURLOPT_COOKIEJAR, 'cookiess.txt');
    $page = curl_exec($c);
    curl_close($c);

    preg_match_all('/<input type="hidden" name="csrfmiddlewaretoken" value="([A-z0-9]{32})"\/>/', $page, $token);

    $c = curl_init();
    curl_setopt($c, CURLOPT_URL, 'https://instagram.com/accounts/login/?force_classic_login');
    curl_setopt($c, CURLOPT_REFERER, 'https://instagram.com/accounts/login/?force_classic_login');
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($c, CURLOPT_POST, true);
    curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($c, CURLOPT_POSTFIELDS, "csrfmiddlewaretoken=".$token[1][0]."&username=[LOGIN]&password=[PASSWORD]");
    curl_setopt($c, CURLOPT_COOKIEFILE, 'cookiess.txt');
    curl_setopt($c, CURLOPT_COOKIEJAR, 'cookiess.txt');
    $page = curl_exec($c);
    curl_close($c);

    $c = curl_init();
    curl_setopt($c, CURLOPT_URL, 'https://instagram.com/aaonishko/');
    curl_setopt($c, CURLOPT_REFERER, 'https://instagram.com/');
    curl_setopt($c, CURLOPT_HTTPHEADER, array(
        'Accept-Language: en-US,en;q=0.8',
        'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.132 Safari/537.36',
        'Accept: */*',
        'X-Requested-With: XMLHttpRequest',
        'Connection: keep-alive'
        ));
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($c, CURLOPT_COOKIEFILE, 'cookiess.txt');
    curl_setopt($c, CURLOPT_COOKIEJAR, 'cookiess.txt');
    $page = curl_exec($c);
    curl_close($c);

    echo $page;

?>

Why page refreshes all the time? Greetings

Shiva
  • 20,575
  • 14
  • 82
  • 112
Mandarynek
  • 51
  • 1
  • 2
  • It might be because of the constant ajax requests the page does. Is there a reason why you shouldn't use the supplied API to program for Instagram? It would really save you some trouble. – al'ein Sep 01 '15 at 11:13
  • I would like like other photos on Instagram but I need an app which requires a special permission. – Mandarynek Sep 01 '15 at 11:18
  • Is there any solution for this problem? – Mandarynek Sep 01 '15 at 11:32
  • At least not one that I know. If there were viable ways to programmatically communicate with the app without an API (by means, upon the user interface which is oriented to human usability), there would be no reason for one to exist. – al'ein Sep 01 '15 at 11:37
  • Please see http://stackoverflow.com/questions/26003063/instagram-login-programatically, it contain working php solution (see last answer) – Vaha Sep 15 '16 at 09:32

0 Answers0