propeopleua/instagram
Composer 安装命令:
composer require propeopleua/instagram
包简介
An easy-to-use PHP Class for accessing Instagram's API.
关键字:
README 文档
README
Note: Starting today (January 30), we are launching three new features on the Instagram Graph API designed to help businesses better manage their organic presence on Instagram. As part of our API changes, we will also be deprecating the older Instagram API Platform over the next two years beginning on July 31, 2018.Please see the full summary here.
Note: On the 17 Nov 2015 [Instagram](http://developers.instagram.coThe following endpoints are deprecated immediately:m/post/133424514006/instagram-platform-update) made changes to their API . Apps created before Nov 17, 2015 wont be affected until Jun 2016. Apps created on or after Nov 17 2015 will require to use their updated API. Please note that this library doesn't yet support their new updates. For more information, please see #182.
A PHP wrapper for the Instagram API. Feedback or bug reports are appreciated.
Composer package available.
Supports Instagram Video and Signed Header.
Requirements
- PHP 5.3 or higher
- cURL
- Registered Instagram App
Get started
To use the Instagram API you have to register yourself as a developer at the Instagram Developer Platform and create an application. Take a look at the uri guidelines before registering a redirect URI. You will receive your client_id and client_secret.
Please note that Instagram mainly refers to »Clients« instead of »Apps«. So »Client ID« and »Client Secret« are the same as »App Key« and »App Secret«.
A good place to get started is the example project.
Installation
I strongly advice using Composer to keep updates as smooth as possible.
$ composer require propeopleua/instagram
Initialize the class
use MetzWeb\Instagram\Instagram; $instagram = new Instagram(array( 'apiKey' => 'YOUR_APP_KEY', 'apiSecret' => 'YOUR_APP_SECRET', 'apiCallback' => 'YOUR_APP_CALLBACK' )); echo "<a href='{$instagram->getLoginUrl()}'>Login with Instagram</a>";
Authenticate user (OAuth2)
// grab OAuth callback code $code = $_GET['code']; $data = $instagram->getOAuthToken($code); echo 'Your username is: ' . $data->user->username;
All methods return the API data json_decode() - so you can directly access the data.
Available methods
Setup Instagram
new Instagram(<array>/<string>);
array if you want to authenticate a user and access its data:
new Instagram(array( 'apiKey' => 'YOUR_APP_KEY', 'apiSecret' => 'YOUR_APP_SECRET', 'apiCallback' => 'YOUR_APP_CALLBACK' ));
string if you only want to access public data:
new Instagram('YOUR_APP_KEY');
Get login URL
getLoginUrl(<array>)
getLoginUrl(array( 'basic', 'likes' ));
Optional scope parameters:
| Scope | Legend | Methods |
|---|---|---|
basic |
to use all user related methods [default] | getUser(), getUserFeed(), getUserFollower() etc. |
relationships |
to follow and unfollow users | modifyRelationship() |
likes |
to like and unlike items | getMediaLikes(), likeMedia(), deleteLikedMedia() |
comments |
to create or delete comments | getMediaComments(), addMediaComment(), deleteMediaComment() |
Get OAuth token
getOAuthToken($code, <true>/<false>)
true : Returns only the OAuth token
false [default] : Returns OAuth token and profile data of the authenticated user
Set / Get access token
- Set the access token, for further method calls:
setAccessToken($token) - Get the access token, if you want to store it for later usage:
getAccessToken()
User methods
Public methods
getUser($id)searchUser()getUserMedia($limit = 0, $min_id = null, $max_id = null)
Authenticated methods
getUser()getUserMedia( <$limit>)
Tag methods
Public methods
getTag($name)getTagMedia($name)searchTags($name)
Instagram videos
Instagram entries are marked with a type attribute (image or video), that allows you to identify videos.
An example of how to embed Instagram videos by using Video.js, can be found in the /example folder.
Please note: Instagram currently doesn't allow to filter videos.
Signed Header
In order to prevent that your access tokens gets stolen, Instagram recommends to sign your requests with a hash of your API secret, the called endpoint and parameters.
- Activate "Enforce Signed Header" in your Instagram client settings.
- Enable the signed-header in your Instagram class:
$instagram->setSignedHeader(true);
- You are good to go! Now, all your requests will be secured with a signed header.
Go into more detail about how it works in the Instagram API Docs.
Pagination
Each endpoint has a maximum range of results, so increasing the limit parameter above the limit won't help (e.g. getUserMedia() has a limit of 90).
That's the point where the "pagination" feature comes into play.
Simply pass an object into the pagination() method and receive your next dataset:
$photos = $instagram->getTagMedia('kitten'); $result = $instagram->pagination($photos);
Iteration with do-while loop.
Samples for redirect URLs
If you need further information about an endpoint, take a look at the Instagram API docs.
Example App
This example project, located in the example/ folder, helps you to get started.
The code is well documented and takes you through all required steps of the OAuth2 process.
Credit for the awesome Instagram icons goes to Ricardo de Zoete Pro.
Changelog
Please see the changelog file for more information.
Credits
Copyright (c) 2011-2015 - Programmed by Christian Metz
Released under the BSD License.
propeopleua/instagram 适用场景与选型建议
propeopleua/instagram 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.57k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 09 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「instagram」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 propeopleua/instagram 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 propeopleua/instagram 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 propeopleua/instagram 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Handles basic OAuth/OAuth2 authentication along with classes for common services
Craft CMS plugin to receive Instagram feed data as variable in templates.
Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
A PSR-7 compatible library for making CRUD API endpoints
Laravel package for the simplification and integration of many of your users most wanted login providers. Installation is a breeze. Never worry about OAuth again.
Magento 2 Social Login extension is designed for quick login to your Magento 2 store without procesing complex register steps
统计信息
- 总下载量: 1.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD
- 更新时间: 2016-09-17