Git Product home page Git Product logo

instagram-graph-api-php-sdk's Introduction

instagram-graph-api-php-sdk

This repository contains the open source PHP SDK that allows you to access the Instagram Graph API from your PHP app.

Installation

Composer

Run this command:

composer require jstolpe/instagram-graph-api-php-sdk

Require the the autoloader.

require_once __DIR__ . '/vendor/autoload.php'; // change path as needed

No Composer

Get the repository

git clone [email protected]:jstolpe/instagram-graph-api-php-sdk.git

Require the custom autoloader.

require_once '/instagram-graph-api-php-sdk/src/instagram/autoload.php'; // change path as needed

Usage

Simple GET example of a user's profile and media posts.

use Instagram\User\BusinessDiscovery;

$config = array( // instantiation config params
    'user_id' => '<IG_USER_ID>',
    'username' => '<USERNAME>', // string of the Instagram account username to get data on
    'access_token' => '<ACCESS_TOKEN>',
);

// instantiate business discovery for a user
$businessDiscovery = new BusinessDiscovery( $config );

// initial business discovery
$userBusinessDiscovery = $businessDiscovery->getSelf();

Simple POST example of posting an image to an Instagram account.

use Instagram\User\Media;
use Instagram\User\MediaPublish;

$config = array( // instantiation config params
    'user_id' => '<USER_ID>',
    'access_token' => '<ACCESS_TOKEN>',
);

// instantiate user media
$media = new Media( $config );

$imageContainerParams = array( // container parameters for the image post
    'caption' => '<CAPTION>', // caption for the post
    'image_url' => '<IMAGE_URL>', // url to the image must be on a public server
);

// create image container
$imageContainer = $media->create( $imageContainerParams );

// get id of the image container
$imageContainerId = $imageContainer['id'];

// instantiate media publish
$mediaPublish = new MediaPublish( $config );

// post our container with its contents to instagram
$publishedPost = $mediaPublish->create( $imageContainerId );

Example of a custom request.

// first we have to instantiate the core Instagram class with our access token
$instagram = new Instagram\Instagram( array(
    'access_token' => '<ACCESS_TOKEN>'
) );

/**
 * Here we are making our request to instagram and specify the endpoint along with our custom params.
 * There is a custom function for get, post, and delete.
 *     $instagram->get()
 *     $instagram->post()
 *     $instagram->delete()
 *
 * Here is the skeleton for the customized call.
 */
$response = $instagram->method( array(
    'endpoint' => '/<ENDPOINT>',
    'params' => array( // query params key/values must match what IG API is expecting for the endpoint
        '<KEY>' => '<VALUE>',
        '<KEY>' => '<VALUE>',
        // ...
    )
) );

Documentation

See the Wiki for the complete documentation.

instagram-graph-api-php-sdk's People

Contributors

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