17

我想知道 ink361 是如何从用户名创建 Instagram RSS 提要的。

示例提要:http: //ink361.com/feed/user/snoopdogg

博文:http: //blog.ink361.com/post/23664609916/new-rss-instagram-feed-feature-on-ink361-com

任何见解将不胜感激。

谢谢。

4

8 回答 8

11

Instagram 有一个可公开访问的 RSS API,很难找到有关它的任何信息,但它适用于标签(我们确实使用它)。

对于标签,语法如下:

http://instagr.am/tags/some-tag-you-want-to-follow/feed/recent.rss

我不确定他们是否对用户的提要有类似的东西,因为我已经说过很难找到关于它的信息,而且它可能会从一天到另一天消失,有利于官方 API,但现在它适用于标签。

这是一篇关于它的官方博客文章(尽管它只涵盖标签):http ://blog.instagram.com/post/8755963247/introducing-hashtags-on-instagram

于 2013-03-26T11:18:44.113 回答
5

@user2543857 's answer was good. Unfortunately, the structure of the Instagram data has changed. As of the date of posting this, this will work. Copy/paste into a file on your PHP server and use like: yoursite.com/instarss.php?user=name_of_instagram_user This will return valid XML/RSS feed.

EDIT!! Naturally, the output of the page/JSON has changed with instagram's new look/feel. Here is updated code (June, 2015):

<?php

if (!isset($_GET['user'])) {
    exit('Not a valid RSS feed. You didn\'nt provide an Instagram user. Send one via a GET variable. Example .../instarss.php?user=snoopdogg');
}

header('Content-Type: text/xml; charset=utf-8');

$html = file_get_contents('http://instagram.com/'.$_GET['user'].'/');
$html = strstr($html, '{"static_root');
$html = strstr($html, '</script>', true);
//$html = substr($html,0,-6);
$html = substr($html, 0, -1);

$data = json_decode($html);

// print_r($data->entry_data->ProfilePage[0]->user->media->nodes);

$rss_feed = '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel>';
$rss_feed .= '<title>'.$_GET['user'].'\'s Instagram Feed</title><atom:link href="http://'.$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"].'" rel="self" type="application/rss+xml" /><link>http://instagram.com/'.$_GET['user'].'</link><description>'.$_GET['user'].'\'s Instagram Feed</description>';

foreach($data->entry_data->ProfilePage[0]->user->media->nodes as $node) {

    $rss_feed .= '<item><title>';

    if(isset($node->caption) && $node->caption != '') {
        $rss_feed .= htmlspecialchars($node->caption, ENT_QUOTES, ENT_HTML5);
    } else {
        $rss_feed .= 'photo';
    }

    // pubdate format could also be: "D, d M Y H:i:s T"
    $rss_feed .= '</title><link>https://instagram.com/p/'.$node->code.'/</link><pubDate>'.date("r", $node->date).'</pubDate><dc:creator><![CDATA['.$_GET['user'].']]></dc:creator><description><![CDATA[<img src="'.$node->display_src.'" />]]></description><guid>https://instagram.com/p/'.$node->code.'/</guid></item>';

} // foreach "node" (photo)

$rss_feed .= '</channel></rss>';

echo $rss_feed;
?>

Actually, don't use the above code. I'll try to maintain this Gist in the future.

EDIT December 2016: I'm tired of chasing the every-changing Instagram output only to screen scrape it and have it change a few months later. I'd say just use the API.. If you are still interested in making an RSS feed from a user's page, this Gist should give you an idea of how to do it.

于 2014-08-28T23:17:20.313 回答
4

感谢托文的小费。

以下是如何在不使用 API 的情况下在您的网站上获取 Instagram 图片的方法。

从 url 和用户名创建 json 文件(将其设置为 cron 作业,每天 X 次)

<?
$html = file_get_contents('http://instagram.com/username/');
$html = strstr($html, '["lib');
$html = strstr($html, '</script>', true);
$html = substr($html,0,-6);
file_put_contents("username.json",$html);
?>

显示来自 json feed 的一些图像

<?
$json = file_get_contents('username.json');
$data = json_decode($json);

$img1 = $data[2][0]->props->userMedia[0]->images->standard_resolution->url;
$img2 = $data[2][0]->props->userMedia[1]->images->standard_resolution->url;
$img3 = $data[2][0]->props->userMedia[2]->images->standard_resolution->url;

print '<img src="'.$img1.'" />';
print '<img src="'.$img2.'" />';
print '<img src="'.$img3.'" />';
?>
于 2013-07-02T18:23:07.170 回答
4

您可以使用/users/user-id/media/recentAPI 端点访问任何 Instagram 用户的提要。此端点需要一个access_token,您可以通过使用 Instagram 授权某些用户(不一定是您为其请求提要的用户)来获取该端点。此处access_token描述了接收过程。

因此,ink361 可能正在做的是access_token为自己(他们在 Instagram 上的用户)获取一个并使用它来/users/user-id/media/recent请求任何其他用户的提要。就那么简单。

于 2013-05-10T12:44:22.350 回答
2

如果我是 ink361,我只会爬取 Instagram 页面,解析 HTML 并将其转换为 RSS。没有API,没有授权,没有问题。

于 2013-04-30T08:58:36.443 回答
2

不幸的是,上面 user2543857 的解决方案不再起作用。这是一个适用于当前个人资料页面源的版本。

从 URL 和用户名创建 JSON 文件(将其设置为 cron 作业,每天 X 次)

<?php
    $json = file_get_contents('http://instagram.com/username');
    $json = strstr($json, '{"entry_data"');
    $json = strstr($json, '</script>', true);
    $json = rtrim($json,';');

    file_put_contents("username.json",$json);
?>

显示来自 JSON 提要的一些图像

<?php
    $json = file_get_contents('username.json');
    $data = json_decode($json,true);

    $img1 = $data['entry_data']['UserProfile'][0]['userMedia'][0]['images']['thumbnail']['url'];
    $img2 = $data['entry_data']['UserProfile'][0]['userMedia'][1]['images']['thumbnail']['url'];
    $img3 = $data['entry_data']['UserProfile'][0]['userMedia'][2]['images']['thumbnail']['url'];

    print '<img src="'.$img1.'" />';
    print '<img src="'.$img2.'" />';
    print '<img src="'.$img3.'" />';
?>
于 2014-01-23T02:50:30.550 回答
-1

您可以使用他们的 API 访问您的 instagram RSS 提要。他们的 API 使用 oAuth2 进行身份验证。我在我的个人博客上使用这种方法在主页上拉入 instagram 图片。我怀疑这就是ink361 网站的工作方式。Ink361 将连接到 instagram api 并通过 instagram 框提示用户登录,他们使用该框允许ink361 访问他们的 instagram 帐户。一旦身份验证成功,ink361 站点将缓存 instagram 收到的令牌,以便他们可以使用相同的令牌定期重复返回 instagram api 进行身份验证。宾果游戏您可以访问用户数据,并且可以从中创建 rss 提要。

于 2013-02-07T12:36:28.037 回答
-1

答案很简单。
要访问用户数据,您只需拥有有效的访问令牌。
ink361 在社交网络http://vk.com/app3225087中有一个应用程序,它将经过身份验证的用户访问令牌存储在 db 中。
它只剩下在 db 中找到一个有效的并获取您想要的任何用户数据

于 2013-09-28T21:03:29.443 回答