我的客户系统需要使用flickr.photos.search API调用从他们的Flickr帐户访问私人照片。我设置它并获取了该调用的生成的URL。当我在浏览器中访问该URL时,它会像输出XML一样输出。如何从flickr.photos.search API调用访问XML?
(API参考:http://www.flickr.com/services/api/flickr.photos.search.html)
然而,在PHP我想访问XML和使用simplexml的PHP扩展显示。我无法弄清楚如何访问XML,因为它不是坐在.xml文件中,而是位于动态URL中。
XML文件(从浏览器)是这样的:
<rsp stat="ok">
<photos page="1" pages="1" perpage="100" total="4">
<photo id="4332852622" owner="[email protected]" secret="xxxxxxxx" server="2760" farm="3" title="building" ispublic="0" isfriend="0" isfamily="0"/>
<photo id="4332113745" owner="[email protected]" secret="xxxxxxx" server="2803" farm="3" title="digging" ispublic="0" isfriend="0" isfamily="0"/>
<photo id="4332852444" owner="[email protected]" secret="xxxxxxx" server="4025" farm="5" title="house" ispublic="0" isfriend="0" isfamily="0"/>
<photo id="4332113699" owner="[email protected]" secret="xxxxxxx" server="2802" farm="3" title="PaulLuomaHab" ispublic="0" isfriend="0" isfamily="0"/>
</photos>
</rsp>
而且随着PHP我想这样的:
$rsp = simplexml_load_file($flickrURL);
foreach($rsp->photos->photo as $photo) {
echo $photo->title;
}
它返回什么都没有。我在这里错过了什么吗?
注:我加echo "Ding!";
以上foreach
循环内,它也呼应叮叮叮叮!这意味着它承认有4张照片,并通过次正确数量的循环!!!
因为某种原因,显然它不满意$ photo-> title?
此外
当我使用print_r($photo)
我得到这个:
SimpleXMLElement Object ([@attributes] => Array ([id] => 4332852622 [owner] => [email protected] [secret] => 88fff62f43 [server] => 2760 [farm] => 3 [title] => building [ispublic] => 0 [isfriend] => 0 [isfamily] => 0))
谢谢,这只是一个快速测试,让它工作。不幸的是,重命名为$ rsp并将其更改为$ rsp-> photos-> photo也无效。 – rhodesjason 2010-02-05 19:13:16