jabranr / instagram-php-sdk
Instagram API的PHP客户端
dev-master
2015-04-11 08:39 UTC
Requires
- php: >=5.3.10
Requires (Dev)
- phpunit/phpunit: 4.3.*
This package is auto-updated.
Last update: 2024-09-24 03:54:28 UTC
README
Instagram API的PHP客户端
免责声明:尽管本项目与著名社交网络同名,但它不是PHP Instagram SDKs的官方版本。此包提供原样,不提供任何保证或承诺,因此请自行承担风险。Instagram是Instagram/Facebook的产品。Instagram。
安装与使用
- 下载最新版本或使用Composer安装。
- 在http://instagram.com/developer/clients/register/注册客户端,并获取
client_id
、client_secret
和redirect_uri
。 - 以下是一个基本使用示例
require('path/to/autoload.php'); use Instagram\InstagramClient; $config = array( 'client_id' => 'CLIENT_ID', 'client_secret' => 'CLIENT_SECRET', 'redirect_uri' => 'http://example.com' ); try { $ig = new InstagramClient( $config ); } catch (Exception $e) { echo $e->getMessage(); } if ( isset($ig) && $ig ) { /** * Get a new access token with OAuth */ if ( isset($_GET['code']) ) { $ig->get_access_token( $fresh = true, $_GET['code'] ); print_r( $ig->get_data() ); /** * Make API requests. See various methods underneath. */ } /** * Or display a login with Instagram link for redirect user for OAuth */ else { echo '<a href="' . $ig->get_oauth_url() . '">Login with Insgatram</a>'; } /** * Or set an existing access token */ $ig->set_access_token( 'A_valid_access_token_obtained_previously' ); print_r( $ig->get_data() ); /** * Make API requests. See various methods underneath. */ }
文档
使用以下方法向Instagram API发送请求。
获取热门媒体
try { $media = $ig->popularMedia( (int) $count = 25 ); $media = json_decode( $media ); print_r( $media ); } catch(Exception $e) { echo $e->getMessage(); }
搜索媒体
/** * Atleast lat and lng are required to make requests to this endpoint */ try { $media = $ig->searchMedia( (float) $lat, (float) $lng, (UNIX_TIMESTAMP) $min_timestamp, (UNIX_TIMESTAMP) $max_timestamp, (int) $distance, (int) $count = 25 ); $media = json_decode( $media ); print_r( $media ); } catch(Exception $e) { echo $e->getMessage(); }
使用ID获取媒体
try { $media = $ig->getMedia( (int) $media_id ); $media = json_decode( $media ); print_r( $media ); } catch(Exception $e) { echo $e->getMessage(); }
许可
MIT许可 - © Jabran Rafique 2014