mbarwick83 / instagram

Laravel 5.* 简单 Instagram API 包。该包正在开发中。

1.11 2017-08-18 19:12 UTC

This package is not auto-updated.

Last update: 2023-11-11 14:51:47 UTC


README

Latest Version on Packagist Software License Total Downloads

Laravel 5.* 简单 Instagram API 包。该包正在开发中,但可以正常工作 - 没有什么疯狂的功能。一直在寻找贡献者。

安装

在项目目录中运行以下命令进行安装

$ composer require mbarwick83/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)。请参阅 许可文件 了解更多信息。