Created
April 9, 2013 18:54
-
-
Save jmathai/5348355 to your computer and use it in GitHub Desktop.
Select a random photo from a user's account
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
// instantiate the API wrapper | |
$op = new OpenPhotoOAuth($host, $consumerKey, $consumerSecret, $oauthToken, $oauthSecret); | |
// call the list API with a limit of 1 photo and access the 'totalPages' property | |
$result = json_decode($op->get('/photos/list.json', array('pageSize' => '1')), 1); | |
$totalPhotos = intval($result['result'][0]['totalPages']); | |
// pick a random number between the first and last photo | |
$randomPage = rand(1, $totalPhotos); | |
// make another API call to get the random photo | |
$result = json_decode($op->get('/photos/list.json', array('pageSize' => '1', 'page' => $randomPage, 'returnSizes' => '800x800', 'generate' => 'true')), 1); | |
$photo = $result['result'][0]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment