pgrimaud / instagram-user-feed

This is a scrapper to easily fetch any feed and interact with Instagram (like, follow, etc.) without OAuth for PHP.
MIT License
873 stars 136 forks source link

midCookie: Call to a member function getValue() on null #305

Open almod90 opened 2 years ago

almod90 commented 2 years ago

Version(s) affected: 6.15.1

Description
Running example with challenge with my own credentials results in the following error:

PHP Fatal error:  Uncaught Error: Call to a member function getValue() on null in /var/www/html/vendor/pgrimaud/instagram-user-feed/src/Instagram/Auth/Checkpoint/Challenge.php:68
Stack trace:
#0 /var/www/html/vendor/pgrimaud/instagram-user-feed/src/Instagram/Auth/Login.php(138): Instagram\Auth\Checkpoint\Challenge->fetchChallengeContent()
#1 /var/www/html/vendor/pgrimaud/instagram-user-feed/src/Instagram/Auth/Login.php(101): Instagram\Auth\Login->checkpointChallenge()
#2 /var/www/html/vendor/pgrimaud/instagram-user-feed/src/Instagram/Api.php(126): Instagram\Auth\Login->process()
#3 /var/www/html/test.php(19): Instagram\Api->login()
#4 {main}
  thrown in /var/www/html/vendor/pgrimaud/instagram-user-feed/src/Instagram/Auth/Checkpoint/Challenge.php on line 68

There are actually no 'mid' cookie inside cookieJar

If I remove everything related with midCookie process walks through, but the code is not sent to email in the end.

Tested this on the 5.6 (php7.3) and 9.2 (php 8.1) laravel versions both the same result

almod90 commented 2 years ago

Actually, my assumption is that on new instagram visit (e.g. in incognito tab) it asks to accept cookies, and only then mid cookie is set via https://www.instagram.com/data/shared_data/ ajax request

h-behme commented 2 years ago

Have the same issue here, but I noticed the cookie notice (e.g. on https://instagram.com/accounts/login/) does not show up, when the ig_did cookie ist set. The value for it should be the device id available in shared_data I think. Then the mid-cookie should be set in response.

h-behme commented 2 years ago

I could bypass the cookie notice by calling https://graphql.instagram.com/graphql/ to "register" (?) the device id and then calling e.g. https://instagram.com/accounts/login/ to get the midCookie. It can look like this:

src/Instagram/Auth/Login.php:L83

$this->client->request('POST', 'https://graphql.instagram.com/graphql/', [
    'headers' => [
        'content-type' => 'application/x-www-form-urlencoded',
    ],
    'body' => http_build_query([
        'doc_id' => 3810865872362889,
        'variables' => json_encode([
            "ig_did" => $data->device_id,
            "first_party_tracking_opt_in" => true,
            "third_party_tracking_opt_in" => false,
            "input" => [
                "client_mutation_id" => 0
            ]
        ]),
    ])
]);

$this->client->request('GET', 'https://instagram.com/accounts/login/', [
    'headers' => [
        'cookie' => 'ig_did=' . $data->device_id . '; csrftoken=' . $data->config->csrf_token . ';',
        'x-csrftoken' => $data->config->csrf_token,
    ],
    'cookies' => $cookieJar,
]);

But maybe they changed to whole process, because then I just get an error "Warning: Undefined property: stdClass::$Challenge" ( src/Instagram/Auth/Checkpoint/Challenge.php:L91 ) because there is not challenge in extra_data?

jailrobeta commented 2 years ago

same problem

ster commented 2 years ago

same problem

aroy314 commented 1 year ago

same, please see https://github.com/pgrimaud/instagram-user-feed/issues/341#issuecomment-1321908720

fabian-mcfly commented 3 weeks ago

Same error here. There is no "mid" cookie, so getValue(); in src/Instagram/Auth/Checkpoint/Challenge.php:69 fails.