【发布时间】:2014-01-10 04:23:36
【问题描述】:
我正在与Cosenary Instagram PHP API Classes 合作从 instagram 获取照片并尝试创建缓存文件以提高速度。下面是sn-p,但它不起作用。
include('conf.php');
require 'bigflannel-instafeed/data/instagram.class.php';
// Initialize class
$instagram = new Instagram($accessToken);
$instagram->setAccessToken($accessToken);
$contents = $instagram->getUserMedia($userID,$settings['count']);
$cache = './instagram.json';
if(file_exists($cache) && filemtime($cache) > time() - 60*60 && filesize($cache) < 10){
// If a cache file exists, and it is newer than 1 hour and file size bigger than 10 bytes, use it
$instaData = file_get_contents($cache);
} else {
$instaData = file_get_contents($contents);
file_put_contents($cache,$instaData);
}
我检查了文件 instagram.json 只是留下了 0 字节大小的空白文件。 我在这里使用代码从其他问题创建缓存文件Caching Instagram API requests using PHP?
-- 编辑--
如果我用 json url 替换 $contents,它可以工作。但是如果我使用 $contents 作为 API 类的一部分,它就不起作用了。
include('conf.php');
require 'bigflannel-instafeed/data/instagram.class.php';
// Initialize class
$instagram = new Instagram($accessToken);
$instagram->setAccessToken($accessToken);
$contents = json_encode($instagram->getUserMedia($userID,$settings['count']));
$cache = './instagram.json';
if(file_exists($cache) && filemtime($cache) > time() - 60*60 && filesize($cache) > 10){
// If a cache file exists, and it is newer than 1 hour, use it
$jsonData = json_decode(file_get_contents($cache));
} else {
$jsonData = json_decode((file_get_contents("https://api.instagram.com/v1/users/3/media/recent/?access_token=180213154.f59def8.f888fe332f7c47e98bd20a44866ef0be&count=34")));
file_put_contents($cache,json_encode($jsonData));
}
【问题讨论】:
-
提供完整的网址,以便我为您做点什么。
-
我编辑了上面的问题。请检查,谢谢。