When logged in to the Instagram web version and clicked on the button for the number of friends, a get request was sent:
https://www.instagram.com/graphql/query/?query_hash=1215Z2b820144728dde7fzab0d904896a&variables={"id":"1234567890","first":24} When I open this link in the browser, then everything is fine, I get json data.
Now I try to do it through Yii2 httpclient :
$client = new Client(); $response = $client->createRequest() ->setMethod('get') ->setUrl('https://www.instagram.com/graphql/query/') ->setData([ 'query_hash' => '1215Z2b820144728dde7facb0d904896a', 'variables' => '{"id":"123456789","first":24}' ]) ->send(); In response, I get a 403 error.
As I understand it, the request still needs to send the necessary headers and cookies.
But the question is - where to get them?
When I open the networks browser, when I click on the link, I see a different list of cookies , headers in request and response .
Then I tried to do this:
$client = new Client(); $firstResponse = $client->createRequest() ->setMethod('get') ->setUrl('https://www.instagram.com/myPage') ->send(); $secondResponse = $client->createRequest() ->setMethod('get') ->setUrl('https://www.instagram.com/graphql/query/') ->setData([ 'query_hash' => '23g53g43g34fDdfsfwe23f23f23f23', 'variables' => '{"id":"1254563214","first":24}' ]) ->setHeaders($firstResponse->getHeaders()) ->setCookies($firstResponse->getCookies()) ->send(); FirstRespons in order to receive cookies , headers , but not much use, not all data comes.
How to do it right?