PHP Classes

Instagram API integration with PHP: Access an Instagram user account with its API

Recommend this page to a friend!
  Info   View files Example   Screenshots Screenshots   View files View files (25)   DownloadInstall with Composer Download .zip   Reputation   Support forum (4)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2023-06-02 (5 months ago) RSS 2.0 feedStarStarStarStar 64%Total: 2,565 All time: 1,495 This week: 78Up
Version Licenses PHP version Categories
instagram 1.12BSD License, GNU ...5.0PHP 5, Web services, Social Networking
Description 

Author

This class can access an Instagram user accounts with its API.

It can send HTTP requests to the Instagram API Web servers using the OAuth protocol to access the account of an user with his permission.

The class retrieves a token that it can use to send subsequent API requests to get the user feed, the user publications, get his followers and who he follows, and his most popular photos.

Picture of Yasir Siddiqui
  Performance   Level  
Name: Yasir Siddiqui is available for providing paid consulting. Contact Yasir Siddiqui .
Classes: 14 packages by
Country: Pakistan Pakistan
Age: 39
All time rank: 3153 in Pakistan Pakistan
Week rank: 122 Up3 in Pakistan Pakistan Equal
Innovation award
Innovation award
Nominee: 8x

Winner: 1x

Example

<?php
session_start
();

if (!isset(
$_SESSION['AccessToken'])) {
   
header('Location: redirect.php?op=getauth');
    die();
}

require_once
'Class.Instagram.php';

$instgram = new Instagram();
$userpublications = json_decode($instgram->getUserPublications(5));

include_once
'header.php';
include_once
'leftmenu.php';
?>

<div id="content">
<div id="content_top"></div>
<div id="content_main">
<?php
foreach ($userpublications->data as $feeddata) {

?>

<h2>&nbsp; </h2>
<p>&nbsp;</p>
<h3><img src="<?php echo $feeddata->user->profile_picture; ?>" width="60" height="60" caption="Profile Image">&nbsp;&nbsp;<?php echo $feeddata->user->username; ?> </h3>
<br><img src="<?php echo $feeddata->images->low_resolution->url; ?>" width="<?php echo $feeddata->images->low_resolution->width; ?>" height="<?php echo $feeddata->images->low_resolution->height; ?>" caption="Feed Image" >
<p>&nbsp;</p>
<p><strong>Caption: </strong><?php echo @$feeddata->caption->text; ?></p>
<p><strong>Comments: </strong><br>
        <?php
       
foreach ($feeddata->comments->data as $commentsdata) {

            echo
"<strong>".$commentsdata->from->username.":</strong> ". $commentsdata->text."<br>";
        }
       
        
?></p>
<p>&nbsp;</p>


<?php
}

if(
count($userpublications->data)==0) {

    echo
"<h2>No Data Available In Your Publications.</h2>";
}
?>
</div>

<?php
include_once 'footer.php';
?>


Details

instagram-apis-with-php

This sample project demonstrates the integration of instagram apis with PHP. It user oAuth authentication and can fetch verity of data.

It can show user?s Feed (user wall), User comments, Uploaded media by a user, Show user?s uploaded photos on Google map with Pins and information windows showing photo, List of users who are following current user, List of users followed by current user, Most popular photos on instagram with comments and users.

Follow the following instructions:

1) First Of all Upload all the files to a publically access able web server so that instagram can redirect user to your server after authentication.

2) Register an application at http://instagram.com/developer/

3) On the registration form enter http://yourwebsite.com/instagram/redirect.php as redirect URI for "OAuth redirect_uri" field.

4) Please note that redirect uri should point to http://yourwebsite.com/instagram/redirect.php otherwise this application is not going to work.

5) After creating the application you will get "CLIENT ID", "CLIENT SECRET" and "REDIRECT URI".

6) Copy those values and open config.php

7) Replace these values in appconfig array. Please note that redirect_url in appconfig should be same as "OAuth redirect_uri" value you entered while registering the App.

8) Hit index.php


Screenshots  
  • feed.PNG
  • map.PNG
  Files folder image Files  
File Role Description
Files folder imageimages (8 files)
Plain text file Class.Instagram.php Class Class File
Accessible without login Plain text file config.php Conf. Configuration script
Accessible without login Plain text file followers.php Example Example script
Accessible without login Plain text file following.php Example Example script
Accessible without login Plain text file footer.php Data Example script
Accessible without login Plain text file header.php Aux. Example script
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file Instructions.txt Doc. Documentation
Accessible without login Plain text file leftmenu.php Example Example script
Accessible without login Plain text file maps.css Data maps css file
Accessible without login Plain text file myfeed.php Example Example script
Accessible without login Plain text file mypublications.php Example Example script
Accessible without login Plain text file popular.php Example Example script
Accessible without login Plain text file publicationsmap.php Example Example script
Accessible without login Plain text file README.md Doc. Auxiliary data
Accessible without login Plain text file redirect.php Example Example script
Accessible without login Plain text file style.css Data Auxiliary data

  Files folder image Files  /  images  
File Role Description
  Accessible without login Image file background.png Data Auxiliary data
  Accessible without login Image file leftmenu_bottom.png Icon Icon image
  Accessible without login Image file leftmenu_link.png Icon Icon image
  Accessible without login Image file leftmenu_top.png Icon Icon image
  Accessible without login Image file link_background.png Icon Icon image
  Accessible without login Image file main_back.png Data Auxiliary data
  Accessible without login Image file main_bottom.png Data Auxiliary data
  Accessible without login Image file main_top.png Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 92%
Total:2,565
This week:0
All time:1,495
This week:78Up
 User Ratings  
 
 All time
Utility:83%StarStarStarStarStar
Consistency:83%StarStarStarStarStar
Documentation:75%StarStarStarStar
Examples:66%StarStarStarStar
Tests:-
Videos:-
Overall:64%StarStarStarStar
Rank:923