doctorconceptual/php-instagram-graph-sdk

Instagram Graph API 的 PHP SDK

v2.0 2020-06-23 12:36 UTC

This package is auto-updated.

Last update: 2024-09-23 22:03:13 UTC


README

这是一个使用 Instagram Graph API 的基本 SDK。我基本上是在发现 Instagram 将关闭他们的旧版 API 并鼓励使用“Instagram Basic Display API”时编写了这个 SDK。

版权 & 许可

除非另有说明,PHP SDK for Instagram Graph API 版权归 Muhammad Talal 所有,© 2020。代码在 MIT 许可证条款下分发。完整的许可文本请参阅 LICENSE 文件。

版本 & 要求

1.0.0, PHP >=5.4.1

安装

首选的安装方法是使用 composer。您可以通过以下方式将库添加为依赖项:

$ composer require doctorconceptual/php-instagram-graph-sdk

用法

创建实例

<?php

use Instagram\Instagram;

// when you create an app for Instagram Basic Display API, 
// you can get client_id, client_secret & redirect_uri from there
// Here is how you can get started:
// https://developers.facebook.com/docs/instagram-basic-display-api/getting-started

$igAPI = new Instagram($clientID, $clientSecret, redirectURI);

获取令牌

$authURL = $igAPI->get_authorize_url();
header("Location: {$authURL}");

// after authorization, it should return to the same URL
$code = $_GET['code'];
$token = $igAPI->get_access_token($code);

// Now that a short-lived token is retrieved, you can
// exchange it with a long-live token
$igAPI->set_access_token($token->access_token);
$token = $this->instagram->get_long_lived_token();
// $token now has a long-lived token which has a life of 60 days
// per Instagram API documentation

获取 Instagram 用户

$igAPI = new Instagram($clientID, $clientSecret);
$igAPI->set_access_token($access_token); // set the previously fetched token
$instagramUserID = 123456; // a valid Instagram user id, this is returned along with the token when fetching token
$user = get_user($instagramUserID);

其他端点可以以类似的方式使用