A
A
atHome2016-10-03 09:22:47
PHP
atHome, 2016-10-03 09:22:47

How to correctly display instagram followers using curl?

Good afternoon!
Can you please tell me how to correctly issue this request in curl to display Instagram followers?

https://www.instagram.com/query/?q=ig_user(4663052){followed_by.first(5){nodes{username}}}

{
  "status": "ok",
  "followed_by": {
    "nodes": [
      {
        "username": "tip_2145_"
      },
      {
        "username": "photographer.kzn"
      },
      {
        "username": "baha__official"
      },
      {
        "username": "evilmagicdm"
      },
      {
        "username": "ruslanius16"
      }
    ]
  }
}

Tried to write like this
$search="https://www.instagram.com/query/?q=ig_user(4663052){followed_by.first(5){nodes{username}}}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $search);
$result = curl_exec($ch);
$res = json_decode($result);

Result:
stdClass Object
(
    [status] => ok
    [followed_by] => stdClass Object
        (
        )
)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2016-10-03
@atHome

Good afternoon.
You go to the specified URL in the browser and see the result, because you are authorized on Instagram, that is, you have already set the necessary cookies in your browser. And curl doesn't have any cookies, so you get an empty result. You either need to substitute cookies and pass them to curl, or log in to Instagram through curl and still save cookies.
To check my version just open your url in some other browser and you will get empty json.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question