Napisałem skrypt, który loguje się do Instagrama bez użycia API i chciałbym, aby skrypt również miał możliwość obserwacji innych osób. Niestety problem stwarza AJAX, który również jest wykonywany. W efekcie wykonywania skryptu nie dostaję nic. Do linii 40 śmiga wszystko jak powinno.
Kod:
<?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); 'Origin: <a href="https://instagram.com'" target="_blank">https://instagram.com'</a>, 'Accept-Encoding: gzip, deflate', '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', 'Content-Type: application/x-www-form-urlencoded', 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Cache-Control: max-age=0', 'Connection: keep-alive' )); curl_setopt($c, CURLOPT_POSTFIELDS, "csrfmiddlewaretoken=".$token[1][0]."&username=ughjktr&password=dataurodzenia2"); 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/web/friendships/223116496/follow/'); curl_setopt($c, CURLOPT_REFERER, 'https://instagram.com/djeb_1/'); curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_FOLLOWLOCATION, true); 'Origin: <a href="https://instagram.com'" target="_blank">https://instagram.com'</a>, 'Accept-Encoding: gzip, deflate', 'X-Instagram-AJAX: 1', '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-Language: en-US,en;q=0.8', 'X-CSRFToken: '.$token[1][0], 'X-Requested-With: XMLHttpRequest', 'Connection: keep-alive', 'Content-Length: 0' )); 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/ajax/bz'); curl_setopt($c, CURLOPT_REFERER, 'https://instagram.com/djeb_1/'); curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_FOLLOWLOCATION, true); curl_setopt($c, CURLOPT_POST, true); 'Origin: <a href="https://instagram.com'" target="_blank">https://instagram.com'</a>, 'Accept-Encoding: gzip, deflate', 'X-Instagram-AJAX: 1', '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', 'Content-Type: application/json; charset=UTF-8', 'Accept-Language: en-US,en;q=0.8', 'X-CSRFToken: '.$token[1][0], 'Accept: application/json, text/javascript, */*; q=0.01', 'Connection: keep-alive', 'X-Requested-With: XMLHttpRequest' )); curl_setopt($c, CURLOPT_POSTFIELDS, '{""q"":[{""page_id"":""2sw885"",""posts"":[[""slipstream:action"",{""description"":""followUserAttempt"",""event_name"":""action"",""extra"":""{\\""gk\\"":{},\\""source\\"":\\""profilePage\\""}"",""hostname"":""instagram.com"",""path"":""/djeb_1/"",""referer"":""https://instagram.com/p/7F5uR-F2YP/?taken-by=djeb_1"",""url"":""https://instagram.com/djeb_1/""},1441119979015,0],[""slipstream:action"",{""description"":""followUserSuccess"",""event_name"":""action"",""extra"":""{\\""gk\\"":{},\\""source\\"":\\""profilePage\\""}"",""hostname"":""instagram.com"",""path"":""/djeb_1/"",""referer"":""https://instagram.com/p/7F5uR-F2YP/?taken-by=djeb_1"",""url"":""https://instagram.com/djeb_1/""},1441119979477,0]],""trigger"":""slipstream:action""}],""ts"":1441119980877}'); curl_setopt($c, CURLOPT_COOKIEFILE, 'cookiess.txt'); curl_setopt($c, CURLOPT_COOKIEJAR, 'cookiess.txt'); $page = curl_exec($c); curl_close($c); ?>
oraz wykonywane zapytania:
Kod
curl "https://instagram.com/web/friendships/223116496/follow/" -X POST -H "Cookie: mid=VeV2pwAEAAFzOFSRssLQ0oNH5Zei; sessionid=IGSCc929c229abe18cbf4f88f2fa86996dc3928cb35750344680b9b901ab7542ba2a"%"3AoK4mQH104a01IiK5MpHPLfULZQ6kOjdM"%"3A"%"7B"%"22_token_ver"%"22"%"3A1"%"2C"%"22_auth_user_id"%"22"%"3A2149829613"%"2C"%"22_token"%"22"%"3A"%"222149829613"%"3A7xiCtr5OmnuUkRRx8fT2kL2Cy0WTlKhu"%"3A16acc902f30747fdc27655e886d82b726ec79bc51f0b66a841b736e01a2b83f5"%"22"%"2C"%"22_auth_user_backend"%"22"%"3A"%"22accounts.backends.CaseInsensitiveModelBackend"%"22"%"2C"%"22last_refreshed"%"22"%"3A1441112449.04923"%"2C"%"22_platform"%"22"%"3A4"%"7D; ig_pr=1; ig_vw=1920; csrftoken=0179af5ebf94270a0e9e42c0e29d3676; ds_user_id=2149829613" -H "Origin: https://instagram.com" -H "Accept-Encoding: gzip, deflate" -H "X-Instagram-AJAX: 1" -H "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" -H "Accept-Language: en-US,en;q=0.8" -H "Accept: */*" -H "Referer: https://instagram.com/djeb_1/" -H "X-CSRFToken: 0179af5ebf94270a0e9e42c0e29d3676" -H "X-Requested-With: XMLHttpRequest" -H "Connection: keep-alive" -H "Content-Length: 0" --compressed
curl "https://instagram.com/ajax/bz" -H "Cookie: mid=VeV2pwAEAAFzOFSRssLQ0oNH5Zei; sessionid=IGSCc929c229abe18cbf4f88f2fa86996dc3928cb35750344680b9b901ab7542ba2a"%"3AoK4mQH104a01IiK5MpHPLfULZQ6kOjdM"%"3A"%"7B"%"22_token_ver"%"22"%"3A1"%"2C"%"22_auth_user_id"%"22"%"3A2149829613"%"2C"%"22_token"%"22"%"3A"%"222149829613"%"3A7xiCtr5OmnuUkRRx8fT2kL2Cy0WTlKhu"%"3A16acc902f30747fdc27655e886d82b726ec79bc51f0b66a841b736e01a2b83f5"%"22"%"2C"%"22_auth_user_backend"%"22"%"3A"%"22accounts.backends.CaseInsensitiveModelBackend"%"22"%"2C"%"22last_refreshed"%"22"%"3A1441112449.04923"%"2C"%"22_platform"%"22"%"3A4"%"7D; ig_pr=1; ig_vw=1920; csrftoken=0179af5ebf94270a0e9e42c0e29d3676; ds_user_id=2149829613" -H "Origin: https://instagram.com" -H "Accept-Encoding: gzip, deflate" -H "X-Instagram-AJAX: 1" -H "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" -H "Content-Type: application/json; charset=UTF-8" -H "Accept-Language: en-US,en;q=0.8" -H "Accept: application/json, text/javascript, */*; q=0.01" -H "Referer: https://instagram.com/djeb_1/" -H "X-CSRFToken: 0179af5ebf94270a0e9e42c0e29d3676" -H "X-Requested-With: XMLHttpRequest" -H "Connection: keep-alive" --data-binary "{""q"":[{""page_id"":""2sw885"",""posts"":[[""slipstream:action"",{""description"":""followUserAttempt"",""event_name"":""action"",""extra"":""{\\""gk\\"":{},\\""source\\"":\\""profilePage\\""}"",""hostname"":""instagram.com"",""path"":""/djeb_1/"",""referer"":""https://instagram.com/p/7F5uR-F2YP/?taken-by=djeb_1"",""url"":""https://instagram.com/djeb_1/""},1441119979015,0],[""slipstream:action"",{""description"":""followUserSuccess"",""event_name"":""action"",""extra"":""{\\""gk\\"":{},\\""source\\"":\\""profilePage\\""}"",""hostname"":""instagram.com"",""path"":""/djeb_1/"",""referer"":""https://instagram.com/p/7F5uR-F2YP/?taken-by=djeb_1"",""url"":""https://instagram.com/djeb_1/""},1441119979477,0]],""trigger"":""slipstream:action""}],""ts"":1441119980877}" --compressed
curl "https://instagram.com/ajax/bz" -H "Cookie: mid=VeV2pwAEAAFzOFSRssLQ0oNH5Zei; sessionid=IGSCc929c229abe18cbf4f88f2fa86996dc3928cb35750344680b9b901ab7542ba2a"%"3AoK4mQH104a01IiK5MpHPLfULZQ6kOjdM"%"3A"%"7B"%"22_token_ver"%"22"%"3A1"%"2C"%"22_auth_user_id"%"22"%"3A2149829613"%"2C"%"22_token"%"22"%"3A"%"222149829613"%"3A7xiCtr5OmnuUkRRx8fT2kL2Cy0WTlKhu"%"3A16acc902f30747fdc27655e886d82b726ec79bc51f0b66a841b736e01a2b83f5"%"22"%"2C"%"22_auth_user_backend"%"22"%"3A"%"22accounts.backends.CaseInsensitiveModelBackend"%"22"%"2C"%"22last_refreshed"%"22"%"3A1441112449.04923"%"2C"%"22_platform"%"22"%"3A4"%"7D; ig_pr=1; ig_vw=1920; csrftoken=0179af5ebf94270a0e9e42c0e29d3676; ds_user_id=2149829613" -H "Origin: https://instagram.com" -H "Accept-Encoding: gzip, deflate" -H "X-Instagram-AJAX: 1" -H "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" -H "Content-Type: application/json; charset=UTF-8" -H "Accept-Language: en-US,en;q=0.8" -H "Accept: application/json, text/javascript, */*; q=0.01" -H "Referer: https://instagram.com/djeb_1/" -H "X-CSRFToken: 0179af5ebf94270a0e9e42c0e29d3676" -H "X-Requested-With: XMLHttpRequest" -H "Connection: keep-alive" --data-binary "{""q"":[{""page_id"":""2sw885"",""posts"":[[""slipstream:action"",{""description"":""followUserAttempt"",""event_name"":""action"",""extra"":""{\\""gk\\"":{},\\""source\\"":\\""profilePage\\""}"",""hostname"":""instagram.com"",""path"":""/djeb_1/"",""referer"":""https://instagram.com/p/7F5uR-F2YP/?taken-by=djeb_1"",""url"":""https://instagram.com/djeb_1/""},1441119979015,0],[""slipstream:action"",{""description"":""followUserSuccess"",""event_name"":""action"",""extra"":""{\\""gk\\"":{},\\""source\\"":\\""profilePage\\""}"",""hostname"":""instagram.com"",""path"":""/djeb_1/"",""referer"":""https://instagram.com/p/7F5uR-F2YP/?taken-by=djeb_1"",""url"":""https://instagram.com/djeb_1/""},1441119979477,0]],""trigger"":""slipstream:action""}],""ts"":1441119980877}" --compressed
Proszę o pomoc.
Pozdrawiam.
P.S Nie zwracajcie uwagi na znaczniki przy Origin, za każdym razem jak je usuwam to pojawiają się na nowo w edytorze na forum.