关闭

php构建RSS

标签: phprssinstagram
131人阅读 评论(0) 收藏 举报
分类:
php构建RSS

虽然说RSS已经过时了,但是还有人喜欢用他。昨天有人在贴吧求助写一个RSS,我心一热就答应其做一下。其中用到了RSSbuilder.class.php和Instagram.class.php。好久没有写代码了,写得有点烂,凑合着看吧。

<?php
/**
 * Instagram Rss Builder
 * name:rss.php
 * BY AntDz
 * 2015-11-18
 (c) Copyright 2015 Administrator. All Rights Reserved.
 * */
require ('rssbuilder.class.php');

header('Content-Type: application/xml; charset=utf-8');
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Fri, 14 Mar 1980 20:53:00 GMT');
header('Last-Modified: ' . date('r'));
header('Pragma: no-cache');

$rss = new RSSBuilder('utf-8', 'http://antdz.iteye.com', 'Instagram RSS', 'Instagram RSS BY AntDz');
$rss -> addDCdata('http://antdz.iteye.com', 'http://antdz.iteye.com', date('r'));
$ver = '2.00'; //rss版本

 /*file_get_contents()读取json
$jsondata = file_get_contents("https://api.instagram.com/v1/users/self/feed?access_token=545490633.2e7067c.2d7378e20775421fadac61fc778965c8");
$arraydata = json_decode($jsondata, TRUE);
$usedata = $arraydata['data'];*/
//获取数组中的data

/*curl读取json*/
require_once ("Instagram.class.php");
$instagram = Instagram::getFeed2('545490633.2e7067c.2d7378e20775421fadac61fc778965c8');
$usedata=$instagram['data'];

foreach ($usedata as $val) {
    $name = "";
    if ($val['user']['full_name'] == "") {
        $name = $val['user']['username'];
    } else {
        $name = $val['user']['full_name'];
    }
    $rss -> addItem('', "<![CDATA[" . $val['caption']['text'] . "]]>", $val['link'], "<![CDATA[" . $val['caption']['text'] . "<br><img  src='" . $val['images']['low_resolution']['url'] . "'/>]]>", $val['type'], date('r', $val['created_time']), "<![CDATA[" . $name . "]]>");
}
$rss -> outputRSS($ver);
?>

项目地址:https://code.csdn.net/antdz/instagram_rss

1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:19186次
    • 积分:481
    • 等级:
    • 排名:千里之外
    • 原创:45篇
    • 转载:5篇
    • 译文:17篇
    • 评论:2条
    文章分类
    最新评论