samsonos/php_instagram

SamsonPHP Instagram module


Keywords
php, instagram, samsonos, samsonphp
License
OpenSSL

Documentation

SamsonPHP Instagram API module

Latest Stable Version Build Status Code Coverage Total Downloads Scrutinizer Code Quality Stories in Ready

Configuration

First of all you need to create configuration class which is working thanks to SamsonPHP module/service configuration:

class InstagramConfig extends \samsonphp\config\Entity
{
    public $appId = 'YOUR_CLIENT_ID';

    public $appSecret = 'YOUR_CLIENT_SECRET';
}

Get list of posts by tag

After creating configuration you can using module methods. First method uses Instagram Tag Endpoints API. Used method is listByTag($tag, $params = array()). Here the second parameter defines your request parameters (count, max_tag_id, min_tag_id).

For example you want to get 10 posts by hashtag adventure:

/** @var \samson\instagram\Instagram $instagram Get SamsonPHP Instagram module */
$instagram = m('instagram');

// Define tag
$myTag = 'adventure';

// Get list of posts
$posts = $instagram->listByTag($myTag, array('count' => 10));

Like post

This method uses Instagram Like Endpoints API. For using it you just need to know users access token for your application, and media identifier. Notice, that this method can toggle like status, so if you create this request for already liked media, this media will unliked.

Simple example:

/** @var \samson\instagram\Instagram $instagram Get SamsonPHP Instagram module */
$instagram = m('instagram');

// Define media to like
$myMediaID = '657988443280050001_25025320';

// Get list of posts
$posts = $instagram->likeMedia($myMediaID, 'ACCESS_TOKEN');

Relationships

This method uses Instagram Relationship Endpoints API. You can user relationships using method setUserRelationship($user_id, $access_token, $action = 'follow'). For using this method you need to know user instagram identifier and his access token. The third parameter defines the relationship.

Simple example:

/** @var \samson\instagram\Instagram $instagram Get SamsonPHP Instagram module */
$instagram = m('instagram');

// Define media to like
$user_id = '12345678';

// Get list of posts
$posts = $instagram->setUserRelationship($user_id, 'ACCESS_TOKEN', 'unfollow');

Subscriptions

This method uses Instagram User Subscriptions API. You are able to create subscriptions for updates of your authenticated users. Use method subscribe($object, $aspect, $verify_token, $callback, $object_id = null) for creating it. Read more about the parameters in instagram API [documentation] (https://www.instagram.com/developer/subscriptions/)

Simple example:

/** @var \samson\instagram\Instagram $instagram Get SamsonPHP Instagram module */
$instagram = m('instagram');

// Get list of posts
$posts = $instagram->subscribe('user', 'media', 'VERIFY_TOKEN', 'callback-function');

This module is working using Instagram API