fast-je
@fast-je
Пишу на php.

Как авторизоваться в Instagram без API?

Всем привет!

В чем вопрос собственно.
Пытаюсь авторизоваться в instagram, но для этого необходимо получить от инсты Set-Cookie, чего я не могу получить через get_headers('https://www.instagram.com', 1) уже и через curl делал, ничего не могу, может просто потому что я тупой, что наиболее вероятно, прошу помочь, направить в нужное русло, что не так делаю, ниже прилагаю код что и как делаю.

$load_cook = get_headers('https://www.instagram.com', 1);
            $load_cook = $this->parseCookies($load_cook['Set-Cookie'], true);

            $paramArr = array(
                'username' => $this->userInsta,
                'password' => $this->passInsta
            );

            $param = http_build_query($paramArr);

            $opts = array(
                'http'=>array(
                    'method' => "POST",
                    'header' => "Content-Type: application/x-www-form-urlencoded;\r\n" .
                        "cookie: csrftoken=".$load_cook['csrftoken']."; mid=".$load_cook['mid'].";\r\n" .
                        "referer: https://www.instagram.com/\r\n" .
                        "x-csrftoken: ".$load_cook['csrftoken']."\r\n" .
                        "user-agent: ".$this->userAgent."\r\n",
                    'content' => $param
                )
            );

            $context = stream_context_create($opts);
            $infa_auth = @file_get_contents('https://www.instagram.com/accounts/login/ajax/', false, $context);


делаю var_dump это строки
$load_cook = get_headers('https://www.instagram.com', 1);


Получаю вот такое

array(17) {
  [0]=>
  string(15) "HTTP/1.1 200 OK"
  ["Content-Type"]=>
  string(24) "text/html; charset=utf-8"
  ["Vary"]=>
  string(40) "Cookie, Accept-Language, Accept-Encoding"
  ["Content-Language"]=>
  string(2) "en"
  ["Date"]=>
  string(29) "Thu, 24 Oct 2019 22:41:15 GMT"
  ["Strict-Transport-Security"]=>
  string(16) "max-age=31536000"
  ["Cache-Control"]=>
  string(44) "private, no-cache, no-store, must-revalidate"
  ["Pragma"]=>
  string(8) "no-cache"
  ["Expires"]=>
  string(29) "Sat, 01 Jan 2000 00:00:00 GMT"
  ["X-Frame-Options"]=>
  string(10) "SAMEORIGIN"
  ["X-Content-Type-Options"]=>
  string(7) "nosniff"
  ["X-XSS-Protection"]=>
  string(1) "0"
  ["x-aed"]=>
  string(2) "11"
  ["Access-Control-Expose-Headers"]=>
  string(18) "X-IG-Set-WWW-Claim"
  ["X-FB-TRIP-ID"]=>
  string(10) "1679558926"
  ["Connection"]=>
  string(5) "close"
  ["Content-Length"]=><code></code>
  string(5) "37471"
}


Делая тот же самый запрос через curl в терминале получаю все необходимые заголовки.

fast:~ fast$ curl -I https://www.instagram.com
HTTP/2 200 
content-type: text/html; charset=utf-8
vary: Cookie, Accept-Language, Accept-Encoding
content-language: en
date: Thu, 24 Oct 2019 22:42:32 GMT
content-length: 37472
strict-transport-security: max-age=31536000
cache-control: private, no-cache, no-store, must-revalidate
pragma: no-cache
expires: Sat, 01 Jan 2000 00:00:00 GMT
x-frame-options: SAMEORIGIN
content-security-policy: report-uri https://www.instagram.com/security/csp_report/; default-src 'self' https://www.instagram.com; img-src https: data: blob:; font-src https: data:; media-src 'self' blob: https://www.instagram.com https://*.cdninstagram.com https://*.fbcdn.net; manifest-src 'self' https://www.instagram.com; script-src 'self' https://instagram.com https://www.instagram.com https://*.www.instagram.com https://*.cdninstagram.com wss://www.instagram.com https://*.facebook.com https://*.fbcdn.net https://*.facebook.net 'unsafe-inline' 'unsafe-eval' blob:; style-src 'self' https://*.www.instagram.com https://www.instagram.com 'unsafe-inline'; connect-src 'self' https://instagram.com https://www.instagram.com https://*.www.instagram.com https://graph.instagram.com https://*.graph.instagram.com https://*.cdninstagram.com https://api.instagram.com wss://www.instagram.com wss://edge-chat.instagram.com https://*.facebook.com https://*.fbcdn.net https://*.facebook.net chrome-extension://boadgeojelhgndaghljhdicfkmllpafd blob:; worker-src 'self' blob: https://www.instagram.com; frame-src 'self' https://instagram.com https://www.instagram.com https://staticxx.facebook.com https://www.facebook.com https://web.facebook.com https://connect.facebook.net https://m.facebook.com; object-src 'none'; upgrade-insecure-requests
x-content-type-options: nosniff
x-xss-protection: 0
x-aed: 11
access-control-expose-headers: X-IG-Set-WWW-Claim
set-cookie: sessionid=""; Domain=instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/
set-cookie: sessionid=""; Domain=.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/
set-cookie: sessionid=""; Domain=i.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/
set-cookie: sessionid=""; Domain=.i.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/
set-cookie: sessionid=""; Domain=www.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/
set-cookie: sessionid=""; Domain=.www.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/
set-cookie: sessionid=""; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/
set-cookie: csrftoken=JRlhuOtpbGp3GcNDgFaVxcresaXvrt37; Domain=.instagram.com; expires=Thu, 22-Oct-2020 22:42:32 GMT; Max-Age=31449600; Path=/; Secure
set-cookie: rur=FRC; Domain=.instagram.com; HttpOnly; Path=/; Secure
set-cookie: mid=XbIo2AAEAAGg67AleuckVi4nWjgZ; Domain=.instagram.com; expires=Sun, 21-Oct-2029 22:42:32 GMT; Max-Age=315360000; Path=/; Secure
x-fb-trip-id: 1679558926
  • Вопрос задан
  • 1197 просмотров
Решения вопроса 1
xmoonlight
@xmoonlight
https://sitecoder.blogspot.com
Может это поможет...
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
Compolomus
@Compolomus Куратор тега PHP
Комполом-быдлокодер
Делайте через пхп на курл, дело вероятно всего в том, что куки ставит js
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
19 апр. 2024, в 23:00
5000 руб./за проект
19 апр. 2024, в 20:43
20000 руб./за проект