wallrio/instafeed

抓取Instagram用户帖子

0.0.3 2018-11-16 18:19 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:42:11 UTC


README

抓取Instagram用户帖子

安装

建议使用 Composer 直接安装。

$ composer require wallrio/instafeed "*"

用法

从账户捕获数据

要捕获用户的信息和发布内容,请使用Profile类和get方法

  • $profile->username(USERNAME_OF_USER);
  • $profile->get(CALLBACK_OPTIONAL);

示例

	use InstaFeed\Profile as Profile;
	$profile = new Profile();

	$profile->username('wallace.rio');
	$instaData = $profile->get();

	print_r($instaData);

使用缓存

  • $profile->useCache = true;
  • $profile->cache->dir(DIRECTORY_OF_CACHE); (可选)

如果省略方法 '$profile->cache->dir',目录将默认为临时目录 (/tmp/instaFeed)。

use InstaFeed\Profile as Profile;
$profile = new Profile();

$profile->useCache = true;
$profile->cache->dir(__DIR__DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR);

$profile->username('wallace.rio');
$instaData = $profile->get();

如果Instagram信息流已更新则运行回调

use InstaFeed\Profile as Profile;
$profile = new Profile();

$profile->useCache = true;

$profile->username('wallace.rio');
$instaData = $profile->get(function(){
	// code to run if instagram feed has updated
});

清理缓存

  • $profile->cache->clear(TIME_TO_CLEAN);

  • TIME_TO_CLEAN: 可选,允许字符串或整数值。

    • 整数:整数将按秒定义。
    • 字符串:输入一个数字和一个字母,用于指定天数、小时数、分钟数和秒数。

时间示例

	$profile->cache->clear('30m');		// 30 minutes
	$profile->cache->clear('2d');		// 2 days
	$profile->cache->clear('5h');		// 5 hours

示例实现

use InstaFeed\Profile as Profile;
$profile = new Profile();

$profile->useCache = true;
$profile->cache->dir(__DIR__DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR);
$profile->cache->clear();

$profile->username('wallace.rio');
$instaData = $profile->get();

许可

instafeed遵循MIT许可。有关更多信息,请参阅许可文件