artin/instagram

适用于 Laravel 5.* 的简单 Instagram API 包。此包正在开发中。

1.11 2017-08-18 19:12 UTC

This package is not auto-updated.

Last update: 2024-09-24 18:58:50 UTC


README

Latest Version on Packagist Software License Total Downloads

适用于 Laravel 5.* 的简单 Instagram API 包。此包正在开发中,但可以正常工作 - 没有什么疯狂之处。始终欢迎贡献者。

安装

要在您的项目目录中安装,请运行以下命令

$ composer require artin/instagram

然后在 config/app.php 中将以下内容添加到 providers 数组中

Mbarwick83\Instagram\InstagramServiceProvider::class

此外,如果您必须(建议您不要),还可以将 Facade 类添加到 config/app.php 中的 aliases 数组中

'Instagram'    => Mbarwick83\Instagram\Facades\Instagram::class

但最好是直接注入类,如下所示(这应该很熟悉)

use Mbarwick83\Instagram\Instagram;

配置

要发布包配置文件,请运行以下 vendor:publish 命令

php artisan vendor:publish

这将创建一个位于您的配置目录中的 instagram.php 文件。在这里您必须输入您的 Instagram API 密钥。在 https://www.instagram.com/developer/clients/register/ 获取您的 API 密钥。

示例用法

// Get login url:
public function index(Instagram $instagram)
{
	return $instagram->getLoginUrl();
	// or Instagram::getLoginUrl();
}

// Get access token on callback, once user has authorized via above method
public function callback(Request $request, Instagram $instagram)
{
	$response = $instagram->getAccessToken($request->code);
	// or $response = Instagram::getAccessToken($request->code);

    if (isset($response['code']) == 400)
    {
        throw new \Exception($response['error_message'], 400);
    }
    
    return $response['access_token'];
}

这些是 API 包中仅有的两个自定义类。其余的 API 都使用 Instagram 的端点进行 POSTDELETEGET 请求,以保持此包的 非常简单。您可以在此处查看所有端点 https://www.instagram.com/developer/endpoints/

您只需指定请求是 POSTDELETEGET 请求,指定 仅端点 以及任何必需的 URL 查询(以数组形式)。例如

public function index(Instagram $instagram)
{
    $data = $instagram->get('v1/users/self', ['access_token' => $access_token]);
    // $data = $instagram->get('v1/users/' $user-id, ['access_token' => $access_token]);
    return $data;
}

极其简单易用!

贡献

有关详细信息,请参阅CONTRIBUTINGCONDUCT

致谢

许可

MIT 许可证(MIT)。有关更多信息,请参阅许可文件