fantasyrock/instagram

Instagram PHP API wrapper

v1.0.8 2015-07-07 21:09 UTC

This package is auto-updated.

Last update: 2024-11-13 10:21:35 UTC


README

Instagram API package

Installation

The reccomended way to install this pacakge is through Composer. The package is available on Packagist

You may require the package by calling composer require fantasyrock/instagram

or add the package manually into your composer.json file:

{
    "require": {
        "fantasyrock/instagram": "*"
    }
}

Package currently works with Guzzle HTTP Client Library and needs to be added into your composer file:

{
    "require": {
        "guzzle/guzzle": "^6.0",
    }
}

Adapters

Currently the packages offers only Guzzle as HTTP adapter but you may easily build your own by extending HttpAbstract and implementing HttpAdapterInterface

Example

<?php 

require 'vendor/autoload.php';

use Instagram\Adapters\Http\GuzzleAdapter;
use Instagram\Instagram;

$adapter = new GuzzleAdapter('access_token');
$factory = new Instagram($adapter);

Sessions

As adapters the package currently only offers support for Native Sessions. However like adapters you may easily build your own by extending SessionAbstract and implementing SessionAdapterInterface

Example

<?php 

require 'vendor/autoload.php';

use Instagram\Adapters\Storage\NativeSessionAdapter;
use Instagram\Security\Credentials;

$storage     = new NativeSessionAdapter();
$credentials = new Credentials(['client_id', 'client_secret', 'redirect_uri'], $storage);

Endpoints

  • User
  • Media
  • Tag
  • Comment
  • Like
  • Relationship
  • Geography
  • Location

Credentials

API needs a valid access token provided by instagram. If your application already has access to user tokens you may pass it directly to the HttpClientAdapter in our case GuzzleAdapter.

To obtain the access key you may generate the login URL using Credentials part of the package and requesting the access token with appropriate adapter

Example

<?php

require 'vendor/autoload.php';

use Instagram\Adapters\Http\GuzzleAdapter;
use Instagram\Adapters\Storage\NativeSessionAdapter;
use Instagram\Security\Credentials;
use Instagram\Instagram;

$storage     = new NativeSessionAdapter();
$credentials = new Credentials([
    'client_id'     => 'YOUR-CLIENT-ID',
    'client_secret' => 'YOUR-CLIENT-SECRET',
    'redirect_uri'  => 'REDIRECT-URI
  ], $storage);

// You may provide additional scope as array of desired additional permissions
$loginUrl = $credentials->getLoginUrl(['basic', 'likes']);

Usage

<?php 

require 'vendor/autoload.php';

use Instagram\Adapters\Http\GuzzleAdapter;
use Instagram\Adapters\Storage\NativeSessionAdapter;
use Instagram\Security\Credentials;
use Instagram\Instagram;

$storage     = new NativeSessionAdapter();
$credentials = new Credentials([
    'client_id'     => 'YOUR-CLIENT-ID', 
    'client_secret' => 'YOUR-CLIENT-SECRET', 
    'redirect_uri'  => 'REDIRECT-URI
  ], $storage);
  
$adapter = new GuzzleAdapter($credentials->getToken());  
$factory = new Instagram($adapter);
  
  
$user = $factory->userClient();
var_dump($user->getInfo());

Issues

Any problems that may arise or for bug spottings please open up an [Issue case] (https://github.com/rockoo/InstagramAPI/issues)