Hi,
I'm having a few problems using the simple_xml and the Flickr API. I'm trying to get a random image from a group pool and print out the results. It works fine when I enter a photo id manually, but when I try and generate a random number I get the above error. Here's my code:
[PHP]
function findAttribute($ object, $attribute) {
foreach($object->attributes() as $a => $b) {
if ($a == $attribute) {
$return = $b;
}
}
if($return) {
return $return;
}
}
$file = "http://flickr.com/services/rest/?method=flickr. groups.pools.ge tPhotos&api_key =API-KEY&group_id=67 4456@N21&per_pa ge=500";
$xml = simplexml_load_ file($file);
$total = $xml->photos['total'];
$photoid = rand(1, $total);
$photo = $xml->photos->photo[$photoid]; /* This is what's causing me problems */
$server = findAttribute($ photo, server);
$id = findAttribute($ photo, id);
$secret = findAttribute($ photo, secret);
$title = findAttribute($ photo, title);
$user = findAttribute($ photo, ownername);
$image = "http://static.flickr.c om/". $server ."/". $id . "_". $secret . ".jpg";
?>
<img src="<?php echo $image; ?>" />
<p><?php echo $title; ?> by <?php echo $user; ?></p>
[/PHP]
I think I know what I'm doing wrong, I just don't know how to rectify it - help!!
I'm having a few problems using the simple_xml and the Flickr API. I'm trying to get a random image from a group pool and print out the results. It works fine when I enter a photo id manually, but when I try and generate a random number I get the above error. Here's my code:
[PHP]
function findAttribute($ object, $attribute) {
foreach($object->attributes() as $a => $b) {
if ($a == $attribute) {
$return = $b;
}
}
if($return) {
return $return;
}
}
$file = "http://flickr.com/services/rest/?method=flickr. groups.pools.ge tPhotos&api_key =API-KEY&group_id=67 4456@N21&per_pa ge=500";
$xml = simplexml_load_ file($file);
$total = $xml->photos['total'];
$photoid = rand(1, $total);
$photo = $xml->photos->photo[$photoid]; /* This is what's causing me problems */
$server = findAttribute($ photo, server);
$id = findAttribute($ photo, id);
$secret = findAttribute($ photo, secret);
$title = findAttribute($ photo, title);
$user = findAttribute($ photo, ownername);
$image = "http://static.flickr.c om/". $server ."/". $id . "_". $secret . ".jpg";
?>
<img src="<?php echo $image; ?>" />
<p><?php echo $title; ?> by <?php echo $user; ?></p>
[/PHP]
I think I know what I'm doing wrong, I just don't know how to rectify it - help!!
Comment