在flickr api中显示错误

时间:2014-01-26 08:13:02

标签: php flickr

我正在使用这个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>";
    }
    ?>

但是它给出了错误

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

可能是什么问题?

1 个答案:

答案 0 :(得分:0)

在初始化phpFlickr对象之前,先将您的API密钥放在上,因为它依赖于此API密钥。

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