Aller au contenu

omnipost/instagram Référence de l’API

Étage
Fournisseur · Omnipost
Version
1.x
Suite de conformité
non branchée
Vérifié en réel
Son README ne le dit pas
Licence
MIT
composer require omnipost/instagram:1.x-dev

Lue dans les fichiers PHP du paquet au commit 799b798a2951 : ses espaces de noms, classes, interfaces et énumérations, leurs constantes, propriétés et méthodes publiques avec leur PHPDoc, et les options que prennent ses fabriques. Rien n’en est exécuté.

Omnipost\Instagram

  • Api class

    The Instagram API with Instagram Login (graph.instagram.com), thin: GET and POST with the account's token, and Meta's errors as Omnipost's - a dead token (code 190, subcodes 463 and 467, HTTP 401) is an UnauthorizedException, anything else a ProviderException with Meta's code (4, 17, 32, 613: the rate limits). Through the application's HTTP client when one is given: the profiler sees the calls, the tests mock them.

    7 methods · 4 constants

  • InstagramProvider class

    An Instagram professional account: who it is, what it posted, and a post published - in Instagram's three steps.

    14 methods · 3 constants

  • InstagramProviderFactory class

    Instagram, through the "Instagram API with Instagram Login": the account and its feed, pictures, carousels, reels and stories published, the long-lived token refreshed, the account connected from a back office.

    7 options

Omnipost\Instagram

Api class

final class Api Api.php:24

The Instagram API with Instagram Login (graph.instagram.com), thin: GET and POST with the account's token, and Meta's errors as Omnipost's - a dead token (code 190, subcodes 463 and 467, HTTP 401) is an UnauthorizedException, anything else a ProviderException with Meta's code (4, 17, 32, 613: the rate limits). Through the application's HTTP client when one is given: the profiler sees the calls, the tests mock them.

The token travels in the query, as Meta wants it: it is struck out of every message an exception carries.

const PROVIDER = 'instagram'
const BASE_URI = 'https://graph.instagram.com'
const VERSION = 'v23.0'
const RATE_LIMIT_CODES = [4, 17, 32, 613]

Meta's codes for "too many calls": the application's, the user's, the page's, a custom limit.

Api::__construct()

public function __construct(?string $accessToken = null, readonly string $baseUri = self::BASE_URI, readonly string $version = self::VERSION, ?HttpClientInterface $http = null)

Api::accessToken()

public function accessToken(): ?string

Api::setAccessToken()

public function setAccessToken(string $accessToken): void

The token every call from now on goes out with (a refreshed one, the one just exchanged).

Api::get()

public function get(string $path, array $query = [], bool $versioned = true): array

Api::post()

public function post(string $path, array $fields = []): array

Api::call()

public function call(string $method, string $url, array $options = []): array

A call as it is, no token added: the OAuth endpoints.

$options

the HTTP client's

Api::url()

public function url(string $path, bool $versioned = true): string

InstagramProvider class

final class InstagramProvider implements PublisherInterface, FeedInterface, RefreshableInterface, OAuthInterface InstagramProvider.php:45

An Instagram professional account: who it is, what it posted, and a post published - in Instagram's three steps.

1. publish() creates a container (Instagram fetches the media from its public URL) and answers PENDING with the container's id; 2. status(container) reads it: PROCESSING while Instagram transcodes; 3. once the container is FINISHED, status() publishes it and answers PUBLISHED with the media's id and its permalink.

The Publication's id changes at step 3, from the container's to the media's: a caller keeps the latest one. status() takes either - a media's id answers PUBLISHED with its permalink. Step 3 must not run twice at once for one container (two workers polling): the caller holds a lock around status().

const AUTHORIZE_URL = 'https://www.instagram.com/oauth/authorize'
const TOKEN_URL = 'https://api.instagram.com/oauth/access_token'
const SCOPES = ['instagram_business_basic', 'instagram_business_content_publish']

Reading the account, publishing on it.

InstagramProvider::__construct()

public function __construct(readonly Api $api, readonly string $user = 'me', readonly ?string $appId = null, readonly ?string $appSecret = null, readonly bool $shareToFeed = true, readonly Validator $validator = new Validator())

InstagramProvider::getName()

public function getName(): string

InstagramProvider::getPlatform()

public function getPlatform(): Platform

InstagramProvider::capabilities()

public function capabilities(): Capabilities

One set of bounds for every kind, the Validator's: the ten media are the carousel's, the 3 s - 15 min the reel's, 9:16 the reel's and the story's ratio, 4:5 and 1:1 the picture's. What depends on the kind is checked by validate().

InstagramProvider::validate()

public function validate(Post $post): array

The post against capabilities(), and against what they cannot say because it depends on the kind: one media unless a carousel (2 to 10), a video for a reel, a picture for a picture, 9:16 for a reel.

InstagramProvider::publish()

public function publish(Post $post): Publication

InstagramProvider::status()

public function status(string $publicationId): Publication

Where a publication stands, by its container's id - published here once Instagram has finished with it - or by its media's id.

InstagramProvider::delete()

public function delete(string $publicationId): void

InstagramProvider::account()

public function account(): Account

InstagramProvider::feed()

public function feed(?string $cursor = null, int $limit = 25): Feed

InstagramProvider::token()

public function token(): ?Token

The token the provider holds; when it dies is known from refresh() and exchange() only.

InstagramProvider::refresh()

public function refresh(): Token

Sixty more days for the long-lived token. Instagram refreshes a token at least 24 hours old and not dead yet: past its end the account is connected again.

InstagramProvider::authorizationUrl()

public function authorizationUrl(string $redirectUri, string $state, array $scopes = []): string

InstagramProvider::exchange()

public function exchange(string $code, string $redirectUri): Token

The code for a short-lived token (an hour), that one for the long-lived one (60 days).

InstagramProviderFactory class

final class InstagramProviderFactory extends ProviderFactory InstagramProviderFactory.php:27

Instagram, through the "Instagram API with Instagram Login": the account and its feed, pictures, carousels, reels and stories published, the long-lived token refreshed, the account connected from a back office.

options: access_token: '%env(default::INSTAGRAM_ACCESS_TOKEN)%' # the long-lived token (60 days): everything but the OAuth dance app_id: '%env(default::INSTAGRAM_APP_ID)%' # the Instagram app's id and secret: authorizationUrl(), exchange() app_secret: '%env(default::INSTAGRAM_APP_SECRET)%' user_id: me # the account the token belongs to share_to_feed: true # a reel also shown on the profile's grid api_version: v23.0 base_uri: https://graph.instagram.com

Nothing is required to build the provider: capabilities() and authorizationUrl() need no token. A call that needs one and finds none throws InvalidConfigException.

Options

OptionDefault
access_tokennull
app_idnull
app_secretnull
user_id'me'
share_to_feedtrue
api_versionApi::VERSION
base_uriApi::BASE_URI