Skip to content

Latest commit

 

History

History
175 lines (131 loc) · 4.59 KB

File metadata and controls

175 lines (131 loc) · 4.59 KB

Instagram Private API

PHP7.1 Ready Latest Stable Version Latest Unstable Version Build Status License

Instagram Private API library

Installation

You can install this by using composer

composer require nicklasw/instagram-api

Features

  • Supports asynchronous and parallel requests
  • Easily extendable with new requests
  • Session and device management
  • Access discover feeds (channels, explore, top live)
  • Access direct feeds (inbox, thread)
  • Much more

Usage

Promise pattern

Basic example

use Instagram\SDK\Responses\Exceptions\ApiResponseException;
use Instagram\SDK\DTO\Messages\InboxMessage;
use Instagram\SDK\DTO\Messages\SessionMessage;
use Instagram\SDK\Instagram;

require_once 'vendor/autoload.php';

$instagram = new Instagram();

// Set result mode
$instagram->setMode(Instagram::MODE_PROMISE);

$instagram
    ->login('INSERT_USERNAME', 'INSERT_PASSWORD')
    ->then(function (SessionMessage $envelope) use ($instagram) {
        return $instagram->inbox();
    })->then(function (InboxMessage $envelope) {
        // Outputs the threads
        var_dump($envelope->getInbox()->getThreads());
    })->otherwise(function (ApiResponseException $exception) {
        // Outputs the error message
        var_dump($exception->getEnvelope()->getMessage());
    })
    ->wait();

Flat promise example

use Instagram\SDK\Responses\Exceptions\ApiResponseException;
use Instagram\SDK\DTO\Messages\InboxMessage;
use Instagram\SDK\DTO\Messages\SessionMessage;
use Instagram\SDK\Instagram;

require_once 'vendor/autoload.php';

$instagram = new Instagram();

// Set result mode
$instagram->setMode(Instagram::MODE_PROMISE);

$instagram
    ->login('INSERT_USERNAME', 'INSERT_PASSWORD')
    ->wait();

// Flat promise chain
$threads = $instagram
    ->inbox()
    ->getInbox()
    ->getThreads()
    ->wait();

Unwrap pattern

Basic example

use Instagram\SDK\DTO\General\ItemType;
use Instagram\SDK\Instagram;

require_once 'vendor/autoload.php';

// Initialize the Instagram library
$instagram = new Instagram();

// Authenticate using username and password
$instagram->login('INSERT_USERNAME', 'INSERT_PASSWORD');

// Invoke the request
$envelope = $instagram->inbox();

// Retrieve the inbox
$inbox = $envelope->getInbox();

// Retrieve the first thread in the inbox
if(!$thread = current($inbox->getThreads())) {
    // No thread found
    return;
}

// Retrieve the whole thread including thread items
$thread->whole();

// Iterate through the list of items
foreach ($thread->getItems() as $item) {
    // Check whether the item is of type media
    if ($item->isItemType(ItemType::MEDIA)) {
        // Retrieve the images
        $images = $item->getMedia()->getImages()->getCandidates();

        foreach ($images as $image) {
            // Output the image url
            var_dump($image->getUrl());
        }
    }
}

Exception classes

  • ApiResponseException
    • Generic API response exception, includes envelope
  • BadPasswordException
  • InvalidUserException
  • RateLimitException
  • InvalidResponseException
    • Generic HTTP response exception

Proxy

require_once '/vendor/autoload.php';

// Initialize the Instagram library, pass the client
$instagram = new Instagram();

$instagram->setProxyUri('INSERT_PROXY');

// Authenticate using username and password
$envelope = $instagram->login('INSERT_USERNAME', 'INSERT_PASSWORD')->wait();

// Output the response
var_dump($envelope);

Contributing

  • Fork it!
  • Create your feature branch: git checkout -b my-new-feature
  • Commit your changes: git commit -am 'Useful information about your new features'
  • Push to the branch: git push origin my-new-feature
  • Submit a pull request

Contributors

Credits

  • mgp25 for the inspiration