stubenbaines/instagramphpapi

用于与Instagram API交互的库。

dev-master 2014-03-24 13:52 UTC

This package is not auto-updated.

Last update: 2024-09-28 15:23:43 UTC


README

一个PHP库,用于调用Instagram API。

要求

  • php版本 >= 5.3
  • cURL扩展

用法

有关如何使用Instagram API以及可用端点的概述,请参阅Instagram API文档:http://instagram.com/developer/authentication/

该库支持通过访问令牌进行认证调用以及仅使用客户端ID的非认证调用。

非认证调用

许多Instagram调用可以在不进行用户认证的情况下进行。对于这些调用,只需要一个客户端ID。请访问http://instagram.com/developer/clients/manage/以生成新的客户端ID。

一旦您有了客户端ID,您可以通过传递客户端ID来创建Instaram api对象的一个实例。

$client_id = '[YOUR CLIENT ID]';
$instagram = new Instagram($client_id);
// Now execute an api call to grab popular media and store the response.        
$res = $instagram->get('/media/popular');
var_dump($res);

认证调用

作为认证用户进行调用更为复杂,因为您需要让用户授权您的应用程序,然后应用程序会获得一个访问码,该访问码随后发送到Instagram以生成用于所有API请求的访问令牌。

$client_id = '[YOUR CLIENT ID]';
$redirect = '[URL OF YOUR APP THAT HANDLES ACCESS CODES]';

$instagram = new Instagram($client_id, $client_secret, $redirect);

// Get an authorize URL. User will be asked to give your app permission to their Instagram account and redirect back with access code.
$instagram->getAuthUrl();

// Now take the access code and request an access token.
$instagram->getAccessToken($code);

// Once you have the access token, you can request user info.
$user = $instagram->getUser();

// Or make authenticated api requests.
$res = $instagram->get('/media/popular');

示例

在仓库中有一个名为demo.php的文件,演示了一些非认证调用。demo_auth.php展示了认证调用。在运行之前,请将client_id替换为您自己的客户端ID。

许可

在MIT许可下发布。