Skip to content
This repository has been archived by the owner on Jan 20, 2020. It is now read-only.

aseba/php-instagram-lib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Disclaimer

This is a very lightweight PHP Instagram API Library that I've created to test the API. It is very simple and it works, it may not be the best thing to use in production though.

Required libraries

All requirements are set in the composer.json

How to use

Quick Start

Create an instance of the Instagram object using you Instagram App information.

It is important that the callback_uri to match the one you set up in the app setting or the oauth login url will fail.

use Instagram\Instagram;

$instagram = new Instagram('client_id', 'client_secret', 'callback_uri');

Set an Access Token

$instagram->setAccessToken('Access Token');

Generic request

Create a request to any API endpoint.

The generic method lets you request an endpoint and add parameters to the request.

Examples:

 //recent photos with the hasthag love
$content = $instagram->generic('/tags/love/media/recent');

//liked photos for the user set with the access token
$content = $instagram->generic('/users/self/media/liked');

//search for users by username
$content = $instagram->generic('/users/search', ['q' => 'aseba']);

//get recent media from user
$content = $instagram->generic('user/media/recent');

Comments

We've created two helper methods to make comment processing easier

Post

Use the comment requests to post a message as a comment in an instagram

Link to the documentation in Instagram

$response = $instagram->comment($media_id, $message);

Delete

Remove a comment of an instagram

Link to the documentation in Instagram

$response = $instagram->delete_comment($media_id, $comment_id);

Oauth

Login

You can use getLogin() to get the url to take the user to start the oauth process.

$instagram->getLogin('response type', [scopes]));
  • Response Type is set to code by default.
  • scopes is empty by default.

Example:

$instagram->getLogin('token', ['basic','public_content','comments', 'relationships', 'follower_list']));

Signed requests

If your app requires signed requests you can use the $instagram->sign() to start signing all requests to Instagram.

Full working example

test.php

<?php

set_time_limit(0);
date_default_timezone_set('UTC');
require __DIR__.'/vendor/autoload.php';

use Instagram\Instagram;

$instagram = new Instagram('client_id', 'client_secret', 'callback_uri');
$instagram->setAccessToken('Access Token');
$instagram->sign();
$content = $instagram->generic('tags/love/media/recent');

foreach($content->data as $media) {
  echo($media->caption->text . "\n");
}

About

UNOfficial PHP Instagram API implementation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages