jahudka/libigfeed
Composer 安装命令:
composer require jahudka/libigfeed
包简介
A backend library for embedding an Instagram feed in your website
README 文档
README
a library which makes it a little easier to embed an Instagram feed in your website
This library encapsulates a little part of the logic needed to embed an Instagram feed in a website. Provided with the appropriate credentials it will fetch a list of the latest posts from your Instagram account which you can then persist locally using any persistence layer you wish. Additionally, you can download the media represented by a post for further processing, such as generating responsive thumbnails.
Dependencies
- PHP >= 8.4 with
ext-json symfony/http-client:^7.2
Installation
composer require jahudka/libigfeed
Usage
-
Follow these instructions to create a new Meta App. Don't connect a Business - you'll be using the app in development mode, so it's not needed.
-
When you get add Instagram in Step 6, you'll be asked to choose which authentication path you want to set up: either via Instagram, or via Facebook. Select Instagram.
-
At the top of the following screen, you can find your App ID and secret. Copy those down, you'll need them in a bit.
-
On the same screen, scroll down all the way to Step 3 - Set up Instagram business login. Input your OAuth authentication endpoint URL. You can ignore the generated Instagram authentication URL.
-
Paste the App ID and secret to the constructor of the
IgFeed\Lib\Clientclass like so:// create an instance of the client: $client = new IgFeed\Lib\Client( HttpClient::create(), $appId, $appSecret, $cacheDir . '/instagram.token' // the library will store the token // obtained during the OAuth authentication flow in this file );
-
You also need to set up the OAuth authentication endpoint mentioned in step 4. All this endpoint needs to do is call
$client->exchangeCodeForAccessToken($redirectUri, $code), where$redirectUriis the URL of the endpoint and$codeis the authorization code returned by Instagram from the OAuth authentication flow in thecodequery string parameter. -
To actually trigger the OAuth authentication flow you need to go to a special URL. You usually only need to do this once in a blue moon, because the access token is valid for 60 days and can be renewed automatically, which the library does for you. The way I usually implement this is:
- In the admin dashboard of the website I call
$client->isConnected(). - If it returns
false, I display a warning message with a link to$client->getAuthorizationUrl($redirectUri).
- In the admin dashboard of the website I call
-
When you have successfully authenticated your website you can use the
$client->getLatestMedia()method to get the latest content from your Instagram feed. The method returns aGeneratorofIgFeed\Lib\Mediainstances. This method will also automatically refresh the access token in the background if it's less than 24 hours from expiration.The idea is to set up a cron job to synchronise a local copy of your Instagram feed every couple of hours - that way the access token should safely refresh when needed, and your website shouldn't be slowed down by loading your Instagram content on-demand. You should also use
$client->download($media, $dst)to download the actual media files so that your site doesn't depend on them loading from Instagram.
jahudka/libigfeed 适用场景与选型建议
jahudka/libigfeed 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 104 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 01 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 jahudka/libigfeed 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jahudka/libigfeed 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 104
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-01-08