arillo/silverstripe-instagram-scraper

Silverstripe的Instagram抓取模块

安装: 18

依赖: 0

建议者: 0

安全: 0

星标: 4

关注者: 5

分支: 1

公开问题: 0

类型:silverstripe-module

0.0.3 2018-08-09 08:32 UTC

This package is auto-updated.

Last update: 2024-09-25 21:32:44 UTC


README

简介

此模块提供了一个抓取任务,用于通过标签、用户名或位置抓取最近的记录。记录将被保存在数据库中(InstagramRecord)。

要求

  • php ^7.0.0
  • ext-json
  • guzzlehttp/guzzle ^6.2
  • phptek/jsontext ^1.0.1
  • nathancox/codeeditorfield ^1.3
  • colymba/gridfield-bulk-editing-tools 2.1.x-dev

安装

composer require arillo/silverstripe-instagram-scraper

用法

要抓取instagram记录,可以运行Arillo\InstagramScraper\Tasks\ScraperTask,并使用以下参数:

  • 类型(标签、用户名或位置)
  • 主题(给定类型的查询)

您可以通过命令行运行以下任务(例如,使用cron作业)。

通过标签查询

php framework/cli-script.php dev/tasks/Arillo-InstagramScraper-Tasks-ScraperTask type=hashtag subject=<the_hashtag_to_query>

通过用户名查询

php framework/cli-script.php dev/tasks/Arillo-InstagramScraper-Tasks-ScraperTask type=username subject=<the_username_to_query>

通过位置查询

php framework/cli-script.php dev/tasks/Arillo-InstagramScraper-Tasks-ScraperTask type=location subject=<instagram_location_id>

或者您可以通过浏览器中的dev/tasks部分运行它们。

处理instagram记录

通过主题抓取记录

public function getInstagramRecords()
{
  // get records by topic (subject & type)
  $records = InstagramRecord::by_topic(<subject>, <type>);

  // $records is a data list, the query can be modified...
  return $records
    ->exclude('Hidden', true)
    ->limit(10)
    ->sort('TakenAtTimestamp DESC')
  ;
}

模板使用示例

<% if $InstagramRecords.Exists %>
  <% loop $InstagramRecords %>
    <div>
      <a href="$PostViewPage.Link" title="$Text" target="_blank">
        <img src="$Image('320').URL"  />
      </a>
    </div>
  <% end_loop %>
<% end_if %>

注意

  • 由于速率限制,可能存在从Instagram抓取数据的问题。
  • 请注意,Instagram可能会更改此模块使用的API端点的访问权限。

贡献

如果您发现bug或有功能请求,请发布一个问题并/或发送一个pull request。