Skip to content

Instantly share code, notes, and snippets.

@jmathai
Created April 9, 2013 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmathai/5348355 to your computer and use it in GitHub Desktop.
Save jmathai/5348355 to your computer and use it in GitHub Desktop.
Select a random photo from a user's account
// 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