Code Monkey home page Code Monkey logo

instagram-api's Introduction

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

instagram-api's People

Contributors

nicklaswallgren avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.