简体   繁体   中英

show error in flickr api

I am using this api

   <?php 
    require_once("phpFlickr.php");
    $f = new phpFlickr("$api_key");
    $api_key                 = "my api key";
    $api_secret              = "my api secret";
    $recent = $f->photos_getRecent();
    print_r($recent);

    foreach ($recent['photo'] as $photo) {
        $owner = $f->people_getInfo($photo['owner']);
        echo "<a href='http://www.flickr.com/photos/" . $photo['owner'] . "/" . $photo['id'] . "/'>";
        echo $photo['title'];
        echo "</a> Owner: ";
        echo "<a href='http://www.flickr.com/people/" . $photo['owner'] . "/'>";
        echo $owner['username'];
        echo "</a><br>";
    }
    ?>

but it gives error

Warning: Invalid argument supplied for foreach() in /home/content/27/9937227/html/project/ww/example.php on line 23

What might be the issue?

Put your API key before initializing the phpFlickr object, because it relies on this API key.

<?php 
require_once("phpFlickr.php");
$api_key  = "my api key";
$api_secret = "my api secret";
$f = new phpFlickr($api_key);
/* ... rest of the code ... */

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM