2014-01-26 93 views
0

錯誤我使用這個API顯示在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

可能是什麼問題?

+0

你的問題是什麼? –

+0

嗨,我的問題是我使用此api,但顯示此錯誤: 警告:無效參數爲foreach()提供的/home/content/27/9937227/html/project/ww/example.php在線23 – user3060459

+0

添加錯誤在你的問題。並添加$ recent的內容 –

回答

0

將您的API密鑰之前初始化phpFlickr對象,因爲它依賴於此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 ... */