Last active
July 30, 2018 07:43
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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}\">"; | |
} | |
} | |
?> |
can i iterate this function as well?
This snippet seems to worked for me too:
$instagram->getUserMedia('self', 10)
But the popular feed is broken, any fix for that?
Try!!! This worked for me!!
echo "<img src=\"{$entry->images->standard_resolution->url}\">";
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
It seems you need to specify the limit of returned results explicitly.
This snippet worked for me:
$instagram->getUserMedia('self', 10)