Instagram SDK Release - March 2016

Page created by Janice Turner
 
CONTINUE READING
Instagram SDK
         Release

       March 08, 2016
Contents

1   User Guide                                                                                                                       3
    1.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .     .   .   .   .   .   .   .   3
         1.1.1   Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .      .   .   .   .   .   .   .   3
         1.1.2   Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .    .   .   .   .   .   .   .   3
         1.1.3   License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .     .   .   .   .   .   .   .   4
         1.1.4   Contributing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .    .   .   .   .   .   .   .   4
    1.2 Quickstart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .     .   .   .   .   .   .   .   5
         1.2.1   Getting an access token . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .     .   .   .   .   .   .   .   5
         1.2.2   Sending Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .      .   .   .   .   .   .   .   6
    1.3 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .       .   .   .   .   .   .   .   6
         1.3.1 get($mediaId) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .             .   .   .   .   .   .   .   6
         1.3.2 create($mediaId, $text) . . . . . . . . . . . . . . . . . . . . . . . .                   .   .   .   .   .   .   .   7
         1.3.3 delete($mediaId, $commentId) . . . . . . . . . . . . . . . . . . . .                      .   .   .   .   .   .   .   7
    1.4 Likes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .    .   .   .   .   .   .   .   7
         1.4.1 get($mediaId) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .             .   .   .   .   .   .   .   7
         1.4.2 like($mediaId) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .              .   .   .   .   .   .   .   7
         1.4.3 unlike($mediaId) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .              .   .   .   .   .   .   .   7
    1.5 Locations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .    .   .   .   .   .   .   .   8
         1.5.1 get($id) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .          .   .   .   .   .   .   .   8
         1.5.2 getRecentMedia($id, $minId = null, $maxId = null) . . .                                   .   .   .   .   .   .   .   8
         1.5.3 search($latitude, $longitude, $distance = 1000) . . . . .                                 .   .   .   .   .   .   .   8
         1.5.4 searchByFacebookPlacesId($facebookPlacesId) . . . . . . . .                               .   .   .   .   .   .   .   8
         1.5.5 searchByFoursquareId($foursquareId) . . . . . . . . . . . . . .                           .   .   .   .   .   .   .   8
    1.6 Media . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .    .   .   .   .   .   .   .   8
         1.6.1 get($id) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .          .   .   .   .   .   .   .   8
         1.6.2 getByShortcode($shortcode) . . . . . . . . . . . . . . . . . . . . . .                    .   .   .   .   .   .   .   9
         1.6.3 search($latitude, $longitude, $distance = 1000) . . . . .                                 .   .   .   .   .   .   .   9
    1.7 Tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .   .   .   .   .   .   .   .   9
         1.7.1 get($tag) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .           .   .   .   .   .   .   .   9
         1.7.2 getRecentMedia($tag, $count = null, $minTagId = null,
                 $maxTagId = null) . . . . . . . . . . . . . . . . . . . . . . . . . . . . .             .   .   .   .   .   .   .    9
         1.7.3 search($tag) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .            .   .   .   .   .   .   .    9
         1.7.4 get($id) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .          .   .   .   .   .   .   .    9
         1.7.5 getRecentMedia($id, $minId = null, $maxId = null) . . .                                   .   .   .   .   .   .   .    9
         1.7.6 search($latitude, $longitude, $distance = 1000) . . . . .                                 .   .   .   .   .   .   .   10
         1.7.7 searchByFacebookPlacesId($facebookPlacesId) . . . . . . . .                               .   .   .   .   .   .   .   10
         1.7.8 searchByFoursquareId($foursquareId) . . . . . . . . . . . . . .                           .   .   .   .   .   .   .   10
    1.8 Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .    .   .   .   .   .   .   .   10

                                                                                                                                      i
1.8.1 get($id = ’self’) . . . . . . . . . . . . . . . . . . . . . . . . . . . .             . . . . . .   . .   10
           1.8.2 getMedia($id = ’self’, $count = null, $minId = null,                                   $maxId       =
                 null) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .       . . . . . .   . .   11
          1.8.3 getLikedMedia($count = null, $maxLikeId = null) . . . .                                . . . . . .   . .   11
          1.8.4 search($query, $count = null) . . . . . . . . . . . . . . . . . .                      . . . . . .   . .   11
          1.8.5 find($username) . . . . . . . . . . . . . . . . . . . . . . . . . . . . .              . . . . . .   . .   11
          1.8.6 follows() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .          . . . . . .   . .   11
          1.8.7 followedBy() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .           . . . . . .   . .   12
          1.8.8 requestedBy() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .            . . . . . .   . .   12
          1.8.9 getRelationship($id) . . . . . . . . . . . . . . . . . . . . . . . . .                 . . . . . .   . .   12
          1.8.10 setRelationship($id, $action) . . . . . . . . . . . . . . . . . .                     . . . . . .   . .   12
     1.9 FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .   . . . . . .   . .   12
          1.9.1  Why is there no way to access the users/feed endpoint? . . . . . . . . . . . .        . . . . . .   . .   12
          1.9.2  Why can’t I use a Foursquare V1 ID to search for locations? . . . . . . . . .         . . . . . .   . .   12
     1.10 Developers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .   . . . . . .   . .   13
          1.10.1 Extending core components . . . . . . . . . . . . . . . . . . . . . . . . . .         . . . . . .   . .   13

HTTP Routing Table                                                                                                         15

ii
Instagram SDK, Release

Elogram is an “eloquent” way of accessing Instagram’s API, for PHP 5.5+. It offers:
    • Simple interface for interacting with the web API. Use methods and arguments instead of cURL.
    • Provides an easy-to-use CSRF-protected solution for retrieving access tokens.
    • Well-tested
    • Extensible
    • Makes pagination a breeze.
use Larabros\Elogram\Client;

$client = new Client($clientId, $clientSecret, $accessToken);

header('Content-Type: application/json');
$response = $client->media()->search(51.503349, -0.252271);
echo json_encode($response->get());

$response = $instagram->users()->find('skrawg');
echo json_encode($response->get());

$response = $instagram->users()->follows();
echo json_encode($response->get());

$response = $client->paginate($response, 2);
echo json_encode($response->get());

Contents                                                                                                   1
Instagram SDK, Release

2                        Contents
CHAPTER 1

                                                                                                 User Guide

1.1 Overview

1.1.1 Requirements

        1. PHP 5.5.0
        2. An Instagram client ID and secret

Note: You can create an Instagram app at https://www.instagram.com/developer/clients/register/

1.1.2 Installation

The recommended way to install Elogram is with Composer. Composer is a dependency management tool for PHP
that allows you to declare the dependencies your project needs and installs them into your project.
# Install Composer
curl -sS https://getcomposer.org/installer | php

You can add Elogram as a dependency using the composer.phar CLI:
php composer.phar require larabros/elogram:~1.0

Alternatively, you can specify it as a dependency in your project’s existing composer.json file:
    {
        "require": {
           "larabros/elogram": "~1.0"
        }
}

After installing, you need to require Composer’s autoloader:
require 'vendor/autoload.php';

You can find out more on how to install Composer, configure autoloading, and other best-practices for defining depen-
dencies at getcomposer.org.

                                                                                                                   3
Instagram SDK, Release

1.1.3 License

Licensed using the MIT license.
      Copyright (c) 2016 Hassan Khan 
      Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associ-
      ated documentation files (the “Software”), to deal in the Software without restriction, including without
      limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
      Software, and to permit persons to whom the Software is furnished to do so, subject to the following
      conditions:
      The above copyright notice and this permission notice shall be included in all copies or substantial portions
      of the Software.
      THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
      OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARIS-
      ING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      DEALINGS IN THE SOFTWARE.

1.1.4 Contributing

Contributions are welcome and will be fully credited.
We accept contributions via Pull Requests on Github.

Documentation

Documentation for this project is available at http://elogram.readthedocs.org.
The API reference is available at http://elogram.readthedocs.org/en/latest/_static/api.

Guidelines

    • PSR-2 Coding Standard - The easiest way to apply the Standard is to install PHP Code Sniffer.
    • PHP 5.5 - Elogram has a minimum PHP version requirement of PHP 5.5. Pull requests must not require a PHP
      version greater than PHP 5.5 unless the feature is only utilized conditionally.
    • Add tests! - All pull requests must include unit tests to ensure the change works as expected and to prevent
      regressions.
    • Document any change in behaviour - Make sure the README.md and any other relevant documentation are
      kept up-to-date.
    • Consider our release cycle - We try to follow SemVer v2. Randomly breaking public APIs is not an option.
    • Create feature branches - Don’t ask us to pull from your master branch.
    • One pull request per feature - If you want to do more than one thing, send multiple pull requests.
    • Send coherent history - Make sure each individual commit in your pull request is meaningful. If you had to
      make multiple intermediate commits while developing, please squash them before submitting.

4                                                                                            Chapter 1. User Guide
Instagram SDK, Release

Running tests

In order to contribute, you’ll need to checkout the source from GitHub and install dependencies using Composer:
$ git clone https://github.com/larabros/elogram.git
$ cd elogram && composer install --dev
$ php vendor/bin/phpunit

Reporting a security vulnerability

We want to ensure that Elogram is secure for everyone. If you’ve discovered a security vulnerability, we appreciate
your help in disclosing it to us in a responsible manner.
Publicly disclosing a vulnerability can put the entire community at risk. If you’ve discovered a security concern, please
email us at contact@hassankhan.me. We’ll work with you to make sure that we understand the scope of the issue, and
that we fully address your concern. We consider correspondence sent to this email address our highest priority, and
work to address any issues that arise as quickly as possible.
After a security vulnerability has been corrected, a security hotfix release will be deployed as soon as possible.
Happy coding!

1.2 Quickstart

This page provides a quick introduction to Elogram and introductory examples. If you have not already installed, head
over to the Installation page.

1.2.1 Getting an access token

To make requests to the Instagram API, you need an access token. To do this, first instantiate Instagram - the
$clientId, $clientSecret and $redirectUrl must be the same as in the Instagram Developer Panel:

Creating a Client

use Larabros\Elogram\Client;

$client = new Client($clientId, $clientSecret, null, $redirectUrl);

The constructor accepts the following parameters:
clientId Generated when you create a new application from the Instagram developer panel.
clientSecret Also generated when you create a new application from the Instagram developer panel.
accessToken Assuming you do not currently have one, use null.
redirectUrl The URL to redirect to after a user authorizes the Instagram client.
After instantiating the client, retrieve the the authorization page URL (or retrieve an access token if the user has already
authorized):
// If we don't have an authorization code then get one
if (!isset($_GET['code'])) {
    header('Location: ' . $client->getLoginUrl());
    exit;

1.2. Quickstart                                                                                                           5
Instagram SDK, Release

} else {
    $token = $client->getAccessToken($_GET['code']);
    echo json_encode($token);
}

// You can now make requests to the API
$client->users()->search('skrawg');

1.2.2 Sending Requests

Simple requests

use Larabros\Elogram\Client;

$client   = new Client($clientId, $clientSecret, $accessToken);
$response = $client->users()->find('skrawg');
echo json_encode($response->get());

$response = $client->media()->getByShortcode('9RV6okpRin');
echo json_encode($response->get());

Paginated Requests

The Response object that you receive from making requests contains the data from the multiple requests combined,
including the first one. You can also pass a $limit as an optional parameter to Instagram::paginate(),
which sets the number of pages to request, assuming they are available.
use Larabros\Elogram\Client;

$client   = new Client($clientId, $clientSecret, $accessToken);
$response = $instagram->users()->follows();
echo json_encode($response->get());

$response = $instagram->paginate($response, 2);
echo json_encode($response->get());

$response = $instagram->paginate($response);
echo json_encode($response->get());

1.3 Comments

1.3.1 get($mediaId)

Important: The public_content permission scope is required to get comments for a media object that does not
belong to the owner of the access token.

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->comments()->get('1109588739516340817_268047373');
echo json_encode($response);

6                                                                                     Chapter 1. User Guide
Instagram SDK, Release

1.3.2 create($mediaId, $text)

Important: The public_content permission scope is required to create comments for a media object that does
not belong to the owner of the access token.

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->comments()->create('1109588739516340817_268047373', 'A comment');
echo json_encode($response);

1.3.3 delete($mediaId, $commentId)

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->comments()->delete('1109588739516340817_268047373', 3);
echo json_encode($response);

1.4 Likes

1.4.1 get($mediaId)

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->likes()->get('1109588739516340817_268047373');
echo json_encode($response);

1.4.2 like($mediaId)

Important: The public_content permission scope is required to create likes on a media object that does not
belong to the owner of the access token.

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->likes()->like('1109588739516340817_268047373');
echo json_encode($response);

1.4.3 unlike($mediaId)

Important: The public_content permission scope is required to delete likes on a media object that does not
belong to the owner of the access token.

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->likes()->unlike('1109588739516340817_268047373');
echo json_encode($response);

1.4. Likes                                                                                              7
Instagram SDK, Release

1.5 Locations

1.5.1 get($id)

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->locations()->get('1');
echo json_encode($response);

1.5.2 getRecentMedia($id, $minId = null, $maxId = null)

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->locations()->getRecentMedia('1');
echo json_encode($response);

1.5.3 search($latitude, $longitude, $distance = 1000)

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->locations()->search(48.858325999999998, 2.294505);
echo json_encode($response);

1.5.4 searchByFacebookPlacesId($facebookPlacesId)

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->locations()->searchByFacebookPlacesId(114226462057675);
echo json_encode($response);

1.5.5 searchByFoursquareId($foursquareId)

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->locations()->searchByFoursquareId('51a2445e5019c80b56934c75');
echo json_encode($response);

1.6 Media

1.6.1 get($id)

Important: The public_content permission scope is required to get a media object that does not belong to the
owner of the access token.

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->media()->get('1109588739516340817_268047373');
echo json_encode($response);

8                                                                                  Chapter 1. User Guide
Instagram SDK, Release

1.6.2 getByShortcode($shortcode)

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->media()->getByShortcode('9RV6okpRin');
echo json_encode($response);

1.6.3 search($latitude, $longitude, $distance = 1000)

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->media()->search(51.503349, -0.252271);
echo json_encode($response);

1.7 Tags

1.7.1 get($tag)

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->tags()->get('snowy');
echo json_encode($response);

1.7.2 getRecentMedia($tag, $count = null, $minTagId = null,
      $maxTagId = null)

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->tags()->getRecentMedia('snowy');
echo json_encode($response);

1.7.3 search($tag)

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->tags()->search('snow');
echo json_encode($response);

Locations

1.7.4 get($id)

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->locations()->get('1');
echo json_encode($response);

1.7.5 getRecentMedia($id, $minId = null, $maxId = null)

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->locations()->getRecentMedia('1');
echo json_encode($response);

1.7. Tags                                                                             9
Instagram SDK, Release

1.7.6 search($latitude, $longitude, $distance = 1000)

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->locations()->search(48.858325999999998, 2.294505);
echo json_encode($response);

1.7.7 searchByFacebookPlacesId($facebookPlacesId)

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->locations()->searchByFacebookPlacesId(114226462057675);
echo json_encode($response);

1.7.8 searchByFoursquareId($foursquareId)

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->locations()->searchByFoursquareId('51a2445e5019c80b56934c75');
echo json_encode($response);

1.8 Users

GET /users/(string:$id)
            Parameters
                  • id – The ID of a user. Default is self.

         Warning: The public_content scope must be set on the access token if the user with $id is not the
         owner of the access token.

     Example request:
     $client   = new Instagram($clientId, $clientSecret, $accessToken);
     $response = $client->users()->get(4);
     echo json_encode($response);

     Example response:
     {
            "username": "mikeyk",
            "first_name": "Mike",
            "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_4_75sq_1292324747_de
            "id": "4",
            "last_name": "Krieger!!"
     }

1.8.1 get($id = ’self’)

Important: The public_content scope is required if a user with $id is not the owner of the access token.

10                                                                                 Chapter 1. User Guide
Instagram SDK, Release

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->users()->get('268047373');
echo json_encode($response);

1.8.2 getMedia($id = ’self’, $count = null, $minId = null, $maxId
      = null)

Important: The public_content scope is required if a user with $id is not the owner of the access token.

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->users()->getMedia('268047373');
echo json_encode($response);

1.8.3 getLikedMedia($count = null, $maxLikeId = null)

Important: This method only works for the owner of the access token.

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->users()->getLikedMedia();
echo json_encode($response);

1.8.4 search($query, $count = null)

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->users()->search('skrawg');
echo json_encode($response);

1.8.5 find($username)

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->users()->find('skrawg');
echo json_encode($response);

1.8.6 follows()

Important: This method only works for the owner of the access token.

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->users()->follows();
echo json_encode($response);

1.8. Users                                                                                                 11
Instagram SDK, Release

1.8.7 followedBy()

Important: This method only works for the owner of the access token.

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->users()->followedBy();
echo json_encode($response);

1.8.8 requestedBy()

Important: This method only works for the owner of the access token.

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->users()->requestedBy();
echo json_encode($response);

1.8.9 getRelationship($id)

Important: This method only works for the owner of the access token.

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->users()->getRelationship('268047373');
echo json_encode($response);

1.8.10 setRelationship($id, $action)

Important: This method only works for the owner of the access token.

$client   = new Instagram($clientId, $clientSecret, $accessToken);
$response = $client->users()->setRelationship(268047373, 'follows');
echo json_encode($response);

1.9 FAQ

1.9.1 Why is there no way to access the users/feed endpoint?

Since the endpoint has been deprecated, we’ve chosen not to implement it in this package.

1.9.2 Why can’t I use a Foursquare V1 ID to search for locations?

Foursquare has been providing new V2 IDs for places for some time now, we do not plan to support them.

12                                                                                          Chapter 1. User Guide
Instagram SDK, Release

1.10 Developers

1.10.1 Extending core components

NativeSessionStore

When using Elogram in a framework, you may want to replace the built-in session storage handler with a custom class
that interacts with the framework. This class must implement the DataStoreInterface. An example is provided below:
use Elogram\Http\Sessions\DataStoreInterface;

class FrameworkSessionStorageHandler implements DataStorageInterface
{
    public function get($key)
    {
        // @TODO: Implement
    }

     public function set($key, $value)
     {
         // @TODO: Implement
     }
}

After creating this class, the Instagram class must be instantiated with an array of options:
use Larabros\Elogram\Client;

$options = ['session_store' => FrameworkSessionStorageHandler::class];
$client = new Client($clientId, $clientSecret, $accessToken, $redirectUrl, $options);

1.10. Developers                                                                                                13
Instagram SDK, Release

14                       Chapter 1. User Guide
HTTP Routing Table

/users
GET /users/(string:$id), 10

                                             15
You can also read