Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Getting basic information from Instagram using PHP

I am trying to get number of total followers that followed me in Instagram. Unfortunately not a single solution is working for me. After a long research only this one is working in my case. I am going to share code may be it will help someone else.

First you have to register your application at instagr.am/developer

Demo | Download

Download Link-2

require 'instagram.class.php';
require 'instagram.config.php';

// Receive OAuth code parameter
$code = $_GET['code'];

// Check whether the user has granted access
if (true === isset($code)) {
     $data = $instagram->getOAuthToken($code);
     if(empty($data->user->username))
     {
        header('Location: index.php');
     }
     else
     {
        session_start();
        $_SESSION['userdetails']=$data;

        $url = 'https://api.instagram.com/v1/users/'.$data->user->id.'?access_token='.$data->access_token;
        $api_response = file_get_contents($url);
        $record = json_decode($api_response);
        
        echo $user=$data->user->username."<br>";
        echo $fullname=$data->user->full_name."<br>";
        echo $bio=$data->user->bio."<br>";
        echo $website=$data->user->website."<br>";
        echo $id=$data->user->id."<br>";
        echo $token=$data->access_token."<br>";
        echo $followed_by = $record->data->counts->followed_by."<br>";
     }
}
else 
{
     // Check whether an error occurred
     if(true === isset($_GET['error']))
     {
        echo 'An error occurred: '.$_GET['error_description'];
     }
}

Please support us, Like us on Facebook.

  1. Very nice blog. Greetings from Indonesia.

    ReplyDelete
  2. Hello Hardik,

    After the new changes in API it is very difficult to get access to API in public_content socpe.
    Is there any way to just scrap the page source of an account and get the no. of followers, since they are shown their publicly.

    ReplyDelete

 

Copyright @ 2017 HKBlog.