Skip to content

Instantly share code, notes, and snippets.

@tpakis
Forked from jonathanbell/Instarss.md
Created August 19, 2016 22:10
Show Gist options
  • Select an option

  • Save tpakis/d9f64868befeef2f16dc3f77b5dd5daa to your computer and use it in GitHub Desktop.

Select an option

Save tpakis/d9f64868befeef2f16dc3f77b5dd5daa to your computer and use it in GitHub Desktop.

Revisions

  1. @jonathanbell jonathanbell revised this gist Mar 31, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion instarss.php
    Original file line number Diff line number Diff line change
    @@ -32,7 +32,7 @@
    if ($data->entry_data->ProfilePage[0]->user->media->nodes) {
    $nodes = $data->entry_data->ProfilePage[0]->user->media->nodes;
    } else {
    exit('Looks like this Instagram account is set to private. We can\'t do much about that now, can we?');
    exit('Looks like this Instagram account is set to private or doesn\'t exist. We can\'t do much about that now, can we?');
    }
    }
    if (isset($_GET['hashtag'])) {
  2. @jonathanbell jonathanbell revised this gist Mar 31, 2016. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions instarss.php
    Original file line number Diff line number Diff line change
    @@ -10,8 +10,6 @@
    exit('Don\'t request both user and hashtag. Request one or the other.');
    }

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

    if (isset($_GET['user'])) {
    $html = file_get_contents('http://instagram.com/'.$_GET['user'].'/');
    }
    @@ -31,12 +29,18 @@
    // print_r($data->entry_data->ProfilePage[0]->user->media->nodes);

    if (isset($_GET['user'])) {
    $nodes = $data->entry_data->ProfilePage[0]->user->media->nodes;
    if ($data->entry_data->ProfilePage[0]->user->media->nodes) {
    $nodes = $data->entry_data->ProfilePage[0]->user->media->nodes;
    } else {
    exit('Looks like this Instagram account is set to private. We can\'t do much about that now, can we?');
    }
    }
    if (isset($_GET['hashtag'])) {
    $nodes = $data->entry_data->TagPage[0]->tag->media->nodes;
    }

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

    $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>';

    if (isset($_GET['user'])) {
  3. @jonathanbell jonathanbell revised this gist Mar 31, 2016. 1 changed file with 37 additions and 5 deletions.
    42 changes: 37 additions & 5 deletions instarss.php
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,23 @@
    <?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');
    if (!isset($_GET['hashtag'])) {
    exit('Not a valid RSS feed. You didn\'nt provide an Instagram user or hashtag. Send one via a GET variable. Example .../instarss.php?user=snoopdogg');
    }
    }

    if (isset($_GET['user']) && isset($_GET['hashtag'])) {
    exit('Don\'t request both user and hashtag. Request one or the other.');
    }

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

    $html = file_get_contents('http://instagram.com/'.$_GET['user'].'/');
    if (isset($_GET['user'])) {
    $html = file_get_contents('http://instagram.com/'.$_GET['user'].'/');
    }
    if (isset($_GET['hashtag'])) {
    $html = file_get_contents('http://instagram.com/explore/tags/'.$_GET['hashtag'].'/');
    }
    $html = strstr($html, '{"country_code');
    $html = strstr($html, '</script>', true);
    $html = substr($html, 0, -1);
    @@ -16,12 +27,27 @@

    $data = json_decode($html);

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

    if (isset($_GET['user'])) {
    $nodes = $data->entry_data->ProfilePage[0]->user->media->nodes;
    }
    if (isset($_GET['hashtag'])) {
    $nodes = $data->entry_data->TagPage[0]->tag->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) {
    if (isset($_GET['user'])) {
    $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>';
    }

    if (isset($_GET['hashtag'])) {
    $rss_feed .= '<title>Photos tagged with: '.$_GET['hashtag'].' on Instagram</title><atom:link href="http://'.$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"].'" rel="self" type="application/rss+xml" /><link>http://instagram.com/explore/tags/'.$_GET['hashtag'].'</link><description>Photos tagged with: '.$_GET['hashtag'].' on Instagram</description>';
    }

    foreach($nodes as $node) {

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

    @@ -32,7 +58,13 @@
    }

    // 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>';
    $rss_feed .= '</title><link>https://instagram.com/p/'.$node->code.'/</link><pubDate>'.date("r", $node->date).'</pubDate>';

    if (isset($_GET['user'])) {
    $rss_feed .= '<dc:creator><![CDATA['.$_GET['user'].']]></dc:creator>';
    }

    $rss_feed .= '<description><![CDATA[<img src="'.$node->display_src.'" />]]></description><guid>https://instagram.com/p/'.$node->code.'/</guid></item>';

    } // foreach "node" (photo)

  4. @jonathanbell jonathanbell revised this gist Dec 30, 2015. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions instarss.php
    Original file line number Diff line number Diff line change
    @@ -7,10 +7,11 @@
    header('Content-Type: text/xml; charset=utf-8');

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

    // for debugging... sigh........
    // echo $html;

    $data = json_decode($html);
    @@ -25,7 +26,7 @@
    $rss_feed .= '<item><title>';

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

    echo $rss_feed;

    ?>
    ?>
  5. @jonathanbell jonathanbell revised this gist Oct 30, 2015. No changes.
  6. @jonathanbell jonathanbell revised this gist Oct 22, 2015. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions instarss.php
    Original file line number Diff line number Diff line change
    @@ -7,11 +7,12 @@
    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, '{"qs');
    $html = strstr($html, '</script>', true);
    //$html = substr($html,0,-6);
    $html = substr($html, 0, -1);

    // echo $html;

    $data = json_decode($html);

    // print_r($data->entry_data->ProfilePage[0]->user->media->nodes);
    @@ -38,4 +39,4 @@

    echo $rss_feed;

    ?>
    ?>
  7. @jonathanbell jonathanbell revised this gist Sep 3, 2015. No changes.
  8. @jonathanbell jonathanbell revised this gist Jun 29, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion instarss.php
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@
    }

    // pubdate format could also be: "D, d M Y H:i:s T"
    $rss_feed .= '</title><link>https://instagram.com/'.$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>';
    $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)

  9. @jonathanbell jonathanbell revised this gist Jun 29, 2015. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions instarss.php
    Original file line number Diff line number Diff line change
    @@ -14,23 +14,25 @@

    $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->UserProfile[0]->userMedia as $user_media) {
    foreach($data->entry_data->ProfilePage[0]->user->media->nodes as $node) {

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

    if(isset($user_media->caption->text) && $user_media->caption->text != '') {
    $rss_feed .= htmlspecialchars($user_media->caption->text, ENT_QUOTES, ENT_HTML5);
    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>'.$user_media->link.'</link><pubDate>'.date("r", $user_media->created_time).'</pubDate><dc:creator><![CDATA[ '.$_GET['user'].' ]]></dc:creator><description><![CDATA[<img src="'.$user_media->images->standard_resolution->url.'" />]]></description><guid>'.$user_media->link.'</guid></item>';
    $rss_feed .= '</title><link>https://instagram.com/'.$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 userMedia (photo)
    } // foreach "node" (photo)

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

  10. @jonathanbell jonathanbell created this gist Aug 29, 2014.
    39 changes: 39 additions & 0 deletions instarss.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    <?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);

    $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->UserProfile[0]->userMedia as $user_media) {

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

    if(isset($user_media->caption->text) && $user_media->caption->text != '') {
    $rss_feed .= htmlspecialchars($user_media->caption->text, 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>'.$user_media->link.'</link><pubDate>'.date("r", $user_media->created_time).'</pubDate><dc:creator><![CDATA[ '.$_GET['user'].' ]]></dc:creator><description><![CDATA[<img src="'.$user_media->images->standard_resolution->url.'" />]]></description><guid>'.$user_media->link.'</guid></item>';

    } // foreach userMedia (photo)

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

    echo $rss_feed;

    ?>