All Projects → Andreyco → Instagram-for-PHP

Andreyco / Instagram-for-PHP

Licence: BSD-2-Clause license
PHP SDK for Instagram API

Programming Languages

PHP
23972 projects - #3 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to Instagram-for-PHP

Laravel Comment
Just another comment system for your awesome Laravel project.
Stars: ✭ 217 (+164.63%)
Mutual labels:  laravel-package
Laravel Views
Laravel package to create beautiful common views like data tables using the TALL stack.
Stars: ✭ 221 (+169.51%)
Mutual labels:  laravel-package
Nexmo Laravel
Add Nexmo functionality such as SMS and voice calling to your Laravel app with this Laravel Service Provider.
Stars: ✭ 250 (+204.88%)
Mutual labels:  laravel-package
Laravel Versionable
⏱️Make Laravel model versionable
Stars: ✭ 218 (+165.85%)
Mutual labels:  laravel-package
Wisteria
Beautiful document tool for your project.
Stars: ✭ 226 (+175.61%)
Mutual labels:  laravel-package
Auth Tests
Always-current tests for Laravel's authentication system. Curated by the community.
Stars: ✭ 230 (+180.49%)
Mutual labels:  laravel-package
Meter
Laravel package to find performance bottlenecks in your laravel application.
Stars: ✭ 204 (+148.78%)
Mutual labels:  laravel-package
madzipper
Wannabe successor of Chumper/Zipper package for Laravel
Stars: ✭ 114 (+39.02%)
Mutual labels:  laravel-package
Wagonwheel
Offer an online version of your Laravel emails to users.
Stars: ✭ 224 (+173.17%)
Mutual labels:  laravel-package
Laravel Localization
Easy localization for Laravel
Stars: ✭ 2,816 (+3334.15%)
Mutual labels:  laravel-package
Sneaker
An easy way to send emails whenever an exception occurs on server.
Stars: ✭ 223 (+171.95%)
Mutual labels:  laravel-package
Clamav Validator
Laravel virus validator based on ClamAV anti-virus scanner
Stars: ✭ 224 (+173.17%)
Mutual labels:  laravel-package
Laravel Multilingual Routes
A package to handle multilingual routes in your Laravel application.
Stars: ✭ 241 (+193.9%)
Mutual labels:  laravel-package
Laravel Terminator
A package to help you clean up your controllers in laravel
Stars: ✭ 217 (+164.63%)
Mutual labels:  laravel-package
Laravel User Activity
Monitor user activity easily!
Stars: ✭ 253 (+208.54%)
Mutual labels:  laravel-package
Laravel State Machine
Winzou State Machine service provider for Laravel
Stars: ✭ 213 (+159.76%)
Mutual labels:  laravel-package
Laravel Query Monitor
Simple artisan command to monitoring triggered queries
Stars: ✭ 230 (+180.49%)
Mutual labels:  laravel-package
nova-rating-field
A Star rating field to use in your Laravel Nova apps.
Stars: ✭ 42 (-48.78%)
Mutual labels:  laravel-package
Translation Sheet
Translating Laravel languages files using a Google Spreadsheet.
Stars: ✭ 254 (+209.76%)
Mutual labels:  laravel-package
Laravel Gitscrum
GitScrum is a Project Management Tool, developed to help entrepreneurs, freelancers, managers, and teams Skyrocket their Productivity with the Agile methodology and Gamification.
Stars: ✭ 2,686 (+3175.61%)
Mutual labels:  laravel-package

instagram-logo-400x400

Instagram PHP API 4.1.1

A PHP wrapper for the Instagram API. Feedback or bug reports are appreciated.

Supports Laravel 5.3, 5.4 & 5.5

Now supports Instagram video responses.

Requirements

  • Registered Instagram App
  • PHP 5.3 or higher
  • cURL

Get started

To use the Instagram API with OAuth you have to register yourself as developer at the Instagram Developer Platform and set up an App. Take a look at the uri guidlines before registering a redirect URI.

Please note that Instagram mainly refers to »Clients« instead of »Apps«. So »Client ID« and »Client Secret« are the same as »App Key« and »App Secret«.

A good place to get started is the example App.

Initialize the class

Pure PHP

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

	$instagram = new Andreyco\Instagram\Client(array(
      'apiKey'      => 'YOUR_APP_KEY',
      'apiSecret'   => 'YOUR_APP_SECRET',
      'apiCallback' => 'YOUR_APP_CALLBACK',
      'scope'       => array('basic'),
    ));

    echo "<a href='{$instagram->getLoginUrl()}'>Login with Instagram</a>";
?>

Laravel

This package offers Laravel support out of the box. These steps are required to setup the package.

Installation

composer require andreyco/instagram

Add Service provider and register Facade

'providers' => array(
    // ...
    Andreyco\Instagram\Support\Laravel\ServiceProvider\Instagram::class,
    // ...
),

'aliases' => array(
    // ...
    'Instagram' => Andreyco\Instagram\Support\Laravel\Facade\Instagram::class,
    // ...
),

Configuration

// Pushlish configuration file.
php artisan vendor:publish --provider="Andreyco\Instagram\Support\Laravel\ServiceProvider\Instagram"

// Edit previously created `config/instagram.php` file
return [
    'clientId'     => '...',
    'clientSecret' => '...',
    'redirectUri'  => '...',
    'scope'        => ['basic'],
]

Usage

In Laravel application, you can access library by simply using Instagram facade, e.g.

Instagram::getLoginUrl();

For usage in pure PHP, you have to create instance of class.

$instagram = new Andreyco\Instagram\Client($config);
$instagram->getLoginUrl()

Authentication example

<?php
    // Generate and redirect to login URL.
    $url = Instagram::getLoginUrl();

    // After allowing to access your profile, grab authorization *code* when redirected back to your page.
    $code = $_GET['code'];
    $data = Instagram::getOAuthToken($code);

    // Now, you have access to authentication token and user profile
    echo 'Your username is: ' . $data->user->username;
    echo 'Your access token is: ' . $data->access_token;
?>

Get user likes example

<?php
    // Set user access token
    Instagram::setAccessToken($accessToken);

    // Get all user likes
    $likes = Instagram::getUserLikes();

    // Take a look at the API response
    echo '<pre>';
    print_r($likes);
    echo '<pre>';
?>

Available methods

Setup Instagram

new Instagram($config: Array|String);

array if you want to authenticate a user and access its data:

new Instagram([
    'apiKey'      => 'YOUR_APP_KEY',
    'apiSecret'   => 'YOUR_APP_SECRET',
    'apiCallback' => 'YOUR_APP_CALLBACK'
]);

string if you only want to access public data:

new Instagram('YOUR_APP_KEY');

Get login URL

getLoginUrl($scope: [Array], $state: [string])

getLoginUrl(['basic', 'likes'], 'uMFYKG5u6v');

Optional scope parameters: To find out more about Scopes, please visit https://www.instagram.com/developer/authorization/

Get OAuth token

getOAuthToken($code, <true>/<false>)

true : Return only the OAuth token false [default] : Returns OAuth token and profile data of the authenticated user

Set / Get access token

Set access token, for further method calls: setAccessToken($token)

Return access token, if you want to store it for later usage: getAccessToken()

User methods

  • getUser()
  • getUser($id)
  • searchUser($name, <$limit>)
  • getUserMedia($id, <$limit>)
  • getUserLikes(<$limit>)
  • getUserMedia(<$id>, <$limit>)
    • if an $id isn't defined, or equals to self it returns the media of the logged in user

Sample responses of the User Endpoints.

Relationship methods

  • getSelfFollows()
  • getSelfFollowedBy()
  • getUserRelationship($id)
  • modifyRelationship($action, $user)
    • $action : Action command (follow / unfollow / block / unblock / approve / deny)
    • $user : Target user id
<?php
    // Follow the user with the ID 1574083
    $instagram->modifyRelationship('follow', 1574083);
?>

Please note that the modifyRelationship() method requires the relationships scope.


Sample responses of the Relationship Endpoints.

Media methods

  • getMedia($id)
  • searchMedia($lat, $lng, <$distance>, <$minTimestamp>, <$maxTimestamp>)
    • $lat and $lng are coordinates and have to be floats like: 48.145441892290336,11.568603515625
    • $distance Radial distance in meter (default is 1km = 1000, max. is 5km = 5000)
    • $minTimestamp All media returned will be taken later than this timestamp (default: 5 days ago)
    • $maxTimestamp All media returned will be taken earlier than this timestamp (default: now)

Sample responses of the Media Endpoints.

Comment methods

  • getMediaComments($id)
  • addMediaComment($id, $text)
    • restricted access: please email apidevelopers[at]instagram.com for access
  • deleteMediaComment($id, $commentID)
    • the comment must be authored by the authenticated user

Please note that the authenticated methods require the comments scope.


Sample responses of the Comment Endpoints.

Tag methods

  • getTag($name)
  • getTagMedia($name)
  • searchTags($name)

Sample responses of the Tag Endpoints.

Likes methods

  • getMediaLikes($id)
  • likeMedia($id)
  • deleteLikedMedia($id)

How to like a Media: Example usage Sample responses of the Likes Endpoints.

All <...> parameters are optional. If the limit is undefined, all available results will be returned.

Instagram videos

Instagram entries are marked with a type attribute (image or video), that allows you to identify videos.

An example of how to embed Instagram videos by using Video.js, can be found in the /example folder.


Please note: Instagram currently doesn't allow to filter videos.


Signed Requests

In order to prevent that your access tokens gets stolen, Instagram recommends to sign your requests with a hash of your API secret, the called endpoint and parameters.

  1. Activate "Enforce Signed Header" in your Instagram client settings.
  2. Enable the signed-requests in your Instagram class:
$instagram->setEnforceSignedRequests(true);

Pagination

Each endpoint has a maximum range of results, so increasing the limit parameter above the limit won't help (e.g. getUserMedia() has a limit of 90).

That's the point where the "pagination" feature comes into play. Simply pass an object into the pagination() method and receive your next dataset:

<?php
    $photos = $instagram->getTagMedia('kitten');

    $result = $instagram->pagination($photos);
?>

Iteration with do-while loop.

Samples for redirect URLs

Registered Redirect URI Redirect URI sent to /authorize Valid?
http://yourcallback.com/ http://yourcallback.com/ yes
http://yourcallback.com/ http://yourcallback.com/?this=that yes
http://yourcallback.com/?this=that http://yourcallback.com/ no
http://yourcallback.com/?this=that http://yourcallback.com/?this=that&another=true yes
http://yourcallback.com/?this=that http://yourcallback.com/?another=true&this=that no
http://yourcallback.com/callback http://yourcallback.com/ no
http://yourcallback.com/callback http://yourcallback.com/callback/?type=mobile yes

If you need further information about an endpoint, take a look at the Instagram API docs.

Example App

Image

This example project, located in the example/ folder, helps you to get started. The code is well documented and takes you through all required steps of the OAuth2 process. Credit for the awesome Instagram icons goes to Ricardo de Zoete Pro.

More examples and tutorials:

Let me know if you have to share a code example, too.

Release notes

You can find release notes here

Credits

Copyright (c) 2014 - Andrej Badin Released under the BSD License.

Instagram-PHP-API contains code taken from Christian Metz's Instagram-PHP-API, also licensed under BSD License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].