flarone / instagram-graph-api
Instagram Graph API PHP 包
1.0.3
2023-10-25 13:49 UTC
Requires
- php: ^5.6|^7.0|^8.0
This package is auto-updated.
Last update: 2024-09-25 15:38:17 UTC
README
此仓库包含一个开源的 PHP SDK,允许您从您的 PHP 应用程序中访问 Instagram Graph API。
安装
Composer
运行此命令
composer require flarone/instagram-graph-api
需要自动加载器。
require_once __DIR__ . '/vendor/autoload.php'; // change path as needed
没有 Composer
获取仓库
git clone git@github.com:flarone/instagram-graph-api.git
需要自定义自动加载器。
require_once '/instagram-graph-api/src/instagram/autoload.php'; // change path as needed
使用方法
用户资料和媒体帖子简单 GET 示例。
use Instagram\User\BusinessDiscovery; $config = array( // instantiation config params 'user_id' => '<IG_USER_ID>', 'username' => '<USERNAME>', // string of the Instagram account username to get data on 'access_token' => '<ACCESS_TOKEN>', ); // instantiate business discovery for a user $businessDiscovery = new BusinessDiscovery( $config ); // initial business discovery $userBusinessDiscovery = $businessDiscovery->getSelf();
向 Instagram 账户发布图像的简单 POST 示例。
use Instagram\User\Media; use Instagram\User\MediaPublish; $config = array( // instantiation config params 'user_id' => '<USER_ID>', 'access_token' => '<ACCESS_TOKEN>', ); // instantiate user media $media = new Media( $config ); $imageContainerParams = array( // container parameters for the image post 'caption' => '<CAPTION>', // caption for the post 'image_url' => '<IMAGE_URL>', // url to the image must be on a public server ); // create image container $imageContainer = $media->create( $imageContainerParams ); // get id of the image container $imageContainerId = $imageContainer['id']; // instantiate media publish $mediaPublish = new MediaPublish( $config ); // post our container with its contents to instagram $publishedPost = $mediaPublish->create( $imageContainerId );
自定义请求示例。
// first we have to instantiate the core Instagram class with our access token $instagram = new Instagram\Instagram( array( 'access_token' => '<ACCESS_TOKEN>' ) ); /** * Here we are making our request to instagram and specify the endpoint along with our custom params. * There is a custom function for get, post, and delete. * $instagram->get() * $instagram->post() * $instagram->delete() * * Here is the skeleton for the customized call. */ $response = $instagram->method( array( 'endpoint' => '/<ENDPOINT>', 'params' => array( // query params key/values must match what IG API is expecting for the endpoint '<KEY>' => '<VALUE>', '<KEY>' => '<VALUE>', // ... ) ) );
文档
查看Wiki以获取完整文档。