PHP Classes
elePHPant
Icontem

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

Recommend this page to a friend!
  Info   View files Documentation   View files View files (27)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2019-04-09 (8 hours ago) RSS 2.0 feedNot enough user ratingsTotal: 135 This week: 1All time: 8,839 This week: 415Up
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.

Recommendations

insta api
i want to integrate in insta

  Performance   Level  
Name: Haridarshan Gorana <contact>
Classes: 1 package by
Country: India India

Details

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  
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

  Files folder image Files  /  src  
File Role Description
Files folder imageExceptions (6 files)
  Plain text file Constants.php Class Class source
  Plain text file HelperFactory.php Class Class source
  Plain text file Instagram.php Class Class source
  Plain text file InstagramApp.php Class Class source
  Plain text file InstagramOAuth.php Class Class source
  Plain text file InstagramRequest.php Class Class source
  Plain text file InstagramResponse.php Class Class source
  Plain text file LoginUrl.php Class Class source

  Files folder image Files  /  src  /  Exceptions  
File Role Description
  Plain text file InstagramException.php Class Class source
  Plain text file InstagramOAuthException.php Class Class source
  Plain text file InstagramRequestException.php Class Class source
  Plain text file InstagramResponseException.php Class Class source
  Plain text file InstagramServerException.php Class Class source
  Plain text file InstagramThrottleException.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Accessible without login Plain text file InstagramTest.php Test Unit test script
  Accessible without login Plain text file sample_env Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:135
This week:1
All time:8,839
This week:415Up