0

I want to fetch the count of Instagram followers but unable to fetch, i am implementing below code to fetch the number.

<?php
$username = 'shubhamtester14';
$response = @file_get_contents( "https://www.instagram.com/$username/?__a=1" );
if ( $response !== false ) {
    $data = json_decode( $response, true );
    if ( $data !== null ) {
        $full_name = $data['graphql']['user']['full_name'];
        $follower  = $data['graphql']['user']['edge_followed_by']['count'];
        echo "{$full_name} have {$follower} followers.";
    }
} else {
    echo 'Username not found.';
}
?>
Yogi Raj
  • 1
  • 1
  • 1
  • 1
    you have to add some additional details to your question – Anantha Raju C Mar 26 '19 at 06:58
  • What do you mean by "unable"? Do you get an error, or the wrong results, or...? Please *edit that information into your question*. – Ian Kemp Mar 26 '19 at 07:08
  • Are you sure file get contents is all json? use regex to get the json and then decode – Baransel A. Mar 26 '19 at 07:11
  • Yes i am geeting error "Username not found." – Yogi Raj Mar 26 '19 at 07:17
  • If I remove the error control operator (`@`), I get a warning: `file_get_contents(https://www.instagram.com/shubhamtester14/?__a=1): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden`. Look at [this](https://stackoverflow.com/questions/4545790/file-get-contents-returns-403-forbidden) – Kévin Bibollet Mar 26 '19 at 07:42

0 Answers0