Skip to content

Instantly share code, notes, and snippets.

@cosenary
Last active July 30, 2018 07:43
Show Gist options
  • Save cosenary/1711218 to your computer and use it in GitHub Desktop.
Save cosenary/1711218 to your computer and use it in GitHub Desktop.
Instagram PHP API - How to get the most recent media published by an Instagram user.
<?php
/**
* Instagram PHP API
* Example for using the getUserMedia() method
*
* @link https://github.com/cosenary/Instagram-PHP-API
* @author Christian Metz
* @since 31.01.2012
*/
require 'Instagram.php';
use MetzWeb\Instagram\Instagram;
// Initialize class
$instagram = new Instagram(array(
'apiKey' => 'YOUR_APP_KEY',
'apiSecret' => 'YOUR_APP_SECRET',
'apiCallback' => 'YOUR_APP_CALLBACK'
));
// Receive OAuth code parameter
$code = $_GET['code'];
// Check whether the user has granted access
if (true === isset($code)) {
// Receive OAuth token object
$data = $instagram->getOAuthToken($code);
// Store user access token
$instagram->setAccessToken($data);
// Now you can call all authenticated user methods
// Get the most recent media published by a user
$media = $instagram->getUserMedia();
foreach ($media->data as $entry) {
echo "<img src=\"{$entry->images->thumbnail->url}\">";
}
}
?>
@axsddlr
Copy link

axsddlr commented Jul 30, 2018

how can i run this file on localhost?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment