ideato/instagram-feed

从Instagram动态中检索数据

0.0.1 2017-10-13 21:05 UTC

This package is auto-updated.

Last update: 2024-09-10 00:10:47 UTC


README

Build Status

从Instagram动态中检索数据

要求

  • PHP 7.1

安装

composer require ideato/instagram-feed

使用

InstagramFeed需要一个Guzzle HTTP客户端和一个Instagram访问令牌。

在此您可以找到生成自己的Instagram访问令牌的工具

    $instagramFeed = new InstagramFeed\InstagramFeed(
        new \GuzzleHttp\Client(),
        'your own access token'
    );
    
    $media = $instagramFeed->getMedia(); //will returns array of InstagramFeed\Model\Media objects

缓存

Instagram API的速率限制较低。这意味着您必须缓存响应以防止错误。该库提供了一个PSR-6缓存装饰器,允许您轻松地缓存响应。

    $instagramFeed = new InstagramFeed\InstagramFeed(
        new \GuzzleHttp\Client(),
        'your own access token'
    );
    
    $instagramCachedFeed = new InstagramFeed\InstagramCachedFeed(
        new \Symfony\Component\Cache\Adapter\FilesystemAdapter(),
        $instagramFeed,
        $ttl //defaults to 600 seconds
    );
    
    $media = $instagramCachedFeed->getMedia(); //will returns array of InstagramFeed\Model\Media objects

Symfony集成

Instagram Feed可以轻松配置为您的Symfony应用程序上的服务。

    services.yml
    
    parameters:
      app_instagram_access_token: 'your own token'
    
    services:
        #if you already defined Guzzle as service, just use yours
        app.guzzle_client:
            class: GuzzleHttp\Client

        app.instagram_feed:
            class: InstagramFeed\InstagramFeed
            arguments:
              - "@app.guzzle_client"
              - "%app_instagram_access_token%"
    
        app.instagram_cached_feed:
            class: InstagramFeed\InstagramCachedFeed
            arguments:
              - "@cache.app"
              - "@app.instagram_feed"
            public: true

然后您可以使用以下方式检索帖子

    $this->get('app.instagram_cached_feed')->getMedia();

待办事项

  • 支持其他API端点
  • 支持其他Instagram类型(例如视频、相册)