3dgoo / silverstripe-instagram-scraper
适用于Silverstripe的Instagram抓取模块
1.0.0
2020-06-04 03:49 UTC
Requires
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-21 15:37:14 UTC
README
适用于Silverstripe的Instagram抓取模块。
要求
安装(使用composer)
$ composer require 3dgoo/silverstripe-instagram-scraper
用法
通过运行以下开发任务导入特定账号的Instagram帖子
php vendor/silverstripe/framework/cli-script.php dev/tasks/import-instagram-posts handle=<handle>
有时Instagram可能需要我们登录才能获取这些数据。这可以通过在我们的.env
文件中添加以下内容来实现
INSTAGRAM_USERNAME="<username>"
INSTAGRAM_PASSWORD="<password>"
一旦我们的Instagram帖子被导入,我们可以使用以下代码显示它们
PageController.php
use X3dgoo\InstagramScraper\Model\InstagramPost;
class PageController extends ContentController
{
public function InstagramPosts($limit = 10)
{
return InstagramPost::get()
->filter([
'Show' => true,
])
->limit($limit);
}
}
Page.ss
<% if $InstagramPosts %>
<div class="instagram-posts">
<% loop $InstagramPosts %>
<div class="instagram-post">
<a href="{$Link}" target="_blank">
<img src="{$ImageThumbnailURL}" alt="{$Caption.LimitWordCount(20).XML}" />
<div class="caption">
$Caption.LimitWordCount(20)
</div>
</a>
</div>
<% end_loop %>
</div>
<% end_if %>