pierrestoffe/php-instagram-graph-sdk

Instagram Graph API 的 PHP SDK

2.2.1 2020-11-09 23:33 UTC

This package is auto-updated.

Last update: 2024-09-21 01:46:04 UTC


README

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

版权 & 许可证

除非另有说明,PHP SDK for Instagram Graph API 的版权为 © 2020 Muhammad Talal。代码根据 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);

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