承接 richardfan1126/php-instagram-api 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

richardfan1126/php-instagram-api

Composer 安装命令:

composer require richardfan1126/php-instagram-api

包简介

PHP Instagram API for PHP 5.3+

关键字:

README 文档

README

#PHP Instagram API

This is a PHP 5.3+ API wrapper for the Instagram API

The API comes with a cURL client (Instagram\Net\CurlClient) to access the Instagran API. You can create your own client, it just has to implement Instagram\Net\ClientInterface.

##The API

All methods that access the API can throw exceptions. If the API request fails for any reason other than an expired/missing access token an exception of type \Instagram\Core\ApiException will be thrown. If the API request fails because of an expired/missing access token an exception of type \Instagram\Core\ApiAuthException will be thrown. You can use this to redirect to your authorization page.

##Authentication

$auth_config = array(
    'client_id'         => '',
    'client_secret'     => '',
    'redirect_uri'      => '',
    'scope'             => array( 'likes', 'comments', 'relationships' )
);

$auth = new Instagram\Auth( $auth_config );
  • Then you have to get the user to authorize your app

$auth->authorize();
  • This will redirect the user to the Instagram authorization page. After authorization Instagram will redirect the user to the url in $auth_config['redirect_uri'] with a code that you will need to obtain an access token

$_SESSION['instagram_access_token'] = $auth->getAccessToken( $_GET['code'] );
  • Then use the access token in your code

$instagram = new Instagram\Instagram;
$instagram->setAccessToken( $_SESSION['instagram_access_token'] );
$current_user = $instagram->getCurrentUser();

##Basic Usage

$instagram = new Instagram\Instagram( $_SESSION['instagram_access_token'] );
$user = $instagram->getUser( $user_id );
$media = $instagram->getMedia( $media_id );
$tag = $instagram->getTag( 'mariokart' );
$location = $instagram->getLocation( 3001881 );
$current_user = $instagram->getCurrentUser();

##Current User

The current user object will give you the currently logged in user

$current_user = $instagram->getCurrentUser();

With this object you can:

  • follow, unfollow, block, and unblock users

$current_user->follow( $user );
$current_user->unfollow( $user );
$current_user->block( $user );
$current_user->unblock( $user );
  • obtain the user's feed, liked media, follow requests

$feed = $current_user->getFeed();
$liked_media = $current_user->getLikedMedia();
  • ignore and approve follow requests

$current_user->ignoreFollowRequest( $user );
$current_user->approveFollowRequest( $user );

You can also perform all the functions you could on a normal user

##Getting Media

Users, tags, locations, and the current user have media associated with them.

This will return recent media from the 4 objects:

$user->getMedia();
$tag->getMedia();
$location->getMedia();
$current_user->getMedia();

You can pass an array of parameters to getMedia(). These parameters will be passed directly to the API. Check the API for a list of available parameters.

$user->getMedia(
    array( 'count' => 3 )
);
$tag->getMedia(
    array( 'max_tag_id' => $max_tag_id )
);
$location->getMedia(
    array( 'max_id' => $max_id )
);

##Images and Videos

You can distinguish between images and videos with Media::getType(). This will return video or image. Video files can be accessed with Media::getStandardResVideo() and Media::getLowResVideo(). The image methods on a video will return a still of the video.

##Collections

When making a call to a method that returns more than one of something (e.g. getMedia(), searchUsers() ), a collection object will be returned. Collections can be iterated, counted, and accessed like arrays.

$user = $instagram->getUser( $user_id );
$media = $user->getMedia();
foreach( $media as $photo ) {
     ...
}
$media_count = count( $media );
$first_photo = $media[0];

The collection object will sometimes have an identifier to the "next page" that can be used to obtain the next page of the collection.

To obtain the identifier for the next page you call getNext() on the collection object.

For example:

$user = $instagram->getUser( $user_id );
$media = $user->getMedia();
$next_page = $media->getNext();

Example usage:

<a href="user_media.php?max_id=<?php echo $next_page ?>">

In user_media.php you would check for a next page when obtaining the user media.

$user = $instagram->getUser( $user_id );
$params = isset( $_GET['max_id'] ) ? array( 'max_id' => $_GET['max_id'] ) : null;
$media = $user->getMedia( $params );

Unfortunately API methods require different params to be passed to them in order to obtain the next set of results (e.g. Tags require the max_tag_id param ).

##Searching

You can search for locations, media, tags, and users.

$locations = $instagram->searchLocations( $lat, $lng );
$media = $instagram->searchMedia( $lat, $lng );
$tags = $instagram->searchTags( 'tag' );
$users = $instagram->searchUsers( 'username' );

richardfan1126/php-instagram-api 适用场景与选型建议

richardfan1126/php-instagram-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 08 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「instagram」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 richardfan1126/php-instagram-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 richardfan1126/php-instagram-api 我们能提供哪些服务?
定制开发 / 二次开发

基于 richardfan1126/php-instagram-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 24
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 115
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-08-22