PHP Classes

PHP Instagram API: Send requests to Instagram API using OAuth tokens

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 212 All time: 8,347 This week: 524Up
Version License PHP version Categories
instagram-php 2.2.3MIT/X Consortium ...5.6PHP 5, Web services, Social Networking
Description 

Author

This package can send requests to Instagram API using OAuth tokens.

It performs the OAuth protocol steps to get a token to access the Instagram API on behalf of a given user.

The main class can create objects that can send HTTP requests to any URL of the Instagram API, so your application can retrieve the request responses.

Picture of Haridarshan Gorana
  Performance   Level  

 

Recommendations

insta api
i want to integrate in insta

Documentation

Instagram-php

Easy-to-use PHP Library for Instagram APIs (Beta)

License Scrutinizer Code Quality Build Status Latest Stable Version Total Downloads Issues Count Code Climate StyleCI

> Note: Any app created before Nov 17, 2015 will continue to function until June 2016. After June 2016, the app will automatically be moved to Sandbox Mode if it wasn't approved through the review process. The Instagram API requires an access_token from authenticated users for each endpoint. We no longer support making requests using just the client_id.

Minimum Requirement

PHP 5.5+ and above
Below 5.5.0, this library won't work

Installation

To install, use composer:

composer require haridarshan/instagram-php

Usage

<?php
require 'vendor/autoload.php';

use Haridarshan\Instagram\Instagram;
use Haridarshan\Instagram\InstagramRequest;
use Haridarshan\Instagram\Exceptions\InstagramOAuthException;
use Haridarshan\Instagram\Exceptions\InstagramResponseException;
use Haridarshan\Instagram\Exceptions\InstagramServerException;

Authorization Code Flow

<?php 

$instagram = new Instagram(array(
  "ClientId" => <InstagramAppClientId>,
  "ClientSecret" => <InstagramAppClientSecret>,
  "Callback" => <callback_url>,
  "State" => <state_param_value> // Optional parameter: if not defined it will generate a random string
));

$scope = [
  "basic",
  "likes",
  "public_content",
  "follower_list", 
  "comments", 
  "relationships"
];

// To get the Instagram Login Url
$insta_url = $instagram->getLoginUrl(["scope" => $scope]);
echo "<a href='{$insta_url}'>Login with Instagram</a>";

Get Access Token

<?php
try {
  $oauth = $instagram->oauth($_GET['code']);
  // To get User's Access Token
  $insta_access_token = $oauth->getAccessToken();
  // To get User's Info Token
  $user_info = $oauth->getUserInfo();
} catch (InstagramOAuthException $e) {
  echo $e->getMessage();
}

Request to Instagram APIs

<?php
try {
  // To get User Profile Details or to make any api call to instagram
  $user = new InstagramRequest($instagram, "/users/self", [ "access_token" => $insta_access_token ]);
  // To get Response
  $user_response = $user->getResponse();
} catch(InstagramResponseException $e) {
  echo $e->getMessage();
} catch(InstagramServerException $e) {
  echo $e->getMessage();
}

$media_comment = new InstagramRequest(
  $instagram,
  "/media/{media-id}/comments", 
  [ "access_token" => $insta_access_token, "text" => "{comment}" ], 
  "POST"
);
$media_response = $media_comment->getResponse();

$delete_comment = new InstagramRequest(
  $instagram,
  "/media/{media-id}/comments/{comment-id}", 
  [ "access_token" => $insta_access_token], 
  "DELETE"
);
$delete_response = $delete_comment->getResponse();

Common Methods

<?php
  // To get User Profile Details or to make any api call to instagram
  $user = new InstagramRequest($instagram, "/users/self", [ "access_token" => $insta_access_token ]);
  // To get Response
  $user_response = $user->getResponse();
  // To get Body part
  $user_body = $user_response->getBody();
  // To get Data part only
  $user_data = $user_response->getData();
  // To get MetaData part
  $user_meta_data = $user_response->getMetaData();


  Files folder image Files (27)  
File Role Description
Files folder imagesrc (8 files, 1 directory)
Files folder imagetests (3 files)
Accessible without login Plain text file .codeclimate.yml Data Auxiliary data
Accessible without login Plain text file .pullapprove.yml Data Auxiliary data
Accessible without login Plain text file .scrutinizer.yml Data Auxiliary data
Accessible without login Plain text file .styleci.yml Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpmd.xml Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:212
This week:0
All time:8,347
This week:524Up