Skip to content

Instantly share code, notes, and snippets.

@corypina
Created November 3, 2018 20:20
Show Gist options
  • Save corypina/01b194ad2adfc89ae7e4ac30f0f08ab5 to your computer and use it in GitHub Desktop.
Save corypina/01b194ad2adfc89ae7e4ac30f0f08ab5 to your computer and use it in GitHub Desktop.
Grab a user's Instagram feed without need for API access
<?php
// Grab and display a user's Instagram feed without need for API access
// Replace USERNAME with username as string.
// IMPORTANT: This relies on the queryfeed.net service, which may or may not always be available
function instagramFeed() {
// Grab and load the feed as a variable
$user = "USERNAME";
$feed = "https://queryfeed.net/instagram?q=" . $user;
$rss = new DOMDocument();
$rss->load($feed);
// Open $images array to hold all the images and their links
$images = array();
// Loop through each 'item' of the feed
foreach ( $rss->getElementsByTagName('item') as $node ) :
$item = array(
// Direct link to the image file
'img' => $node->getElementsByTagName('enclosure')->item(0)->getAttribute('url'),
// Link to the image's Instagram page
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
);
// Add the item to the $images array
array_push( $images, $item );
endforeach;
// Print each item as the image file surrounded by the link to the page
foreach ( $images as $pic ) : ?>
<a class="ig-feed" href="<?php echo $pic['link'] ?>">
<img class="ig-feed" src="<?php echo $pic['img']; ?>"/>
</a>
<?php
endforeach;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment