PHP Flickr照片引入PHP JSON

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP Flickr照片引入PHP JSON相关的知识,希望对你有一定的参考价值。

<?php
$flickrId = 'userId'; // Find your Flickr ID at http://idgettr.com
$flickrrequest = 'http://api.flickr.com/services/feeds/photos_public.gne?id=' . $flickrId . '&format=json';
$flickrci = curl_init($flickrrequest);
curl_setopt($flickrci,CURLOPT_RETURNTRANSFER, TRUE);
$flickrinput = curl_exec($flickrci);
curl_close($flickrci);

// Flickr JSON doesn't come in standard form, some str replace needed

$flickrinput = str_replace('jsonFlickrFeed(','',$flickrinput);
$flickrinput = str_replace('})','}',$flickrinput);

// parameter 'true' is necessary for output as PHP array

$flickrvalue = json_decode($flickrinput,true);
$flickritem =  $flickrvalue['items'];

// echo the channel information

echo "<h3><a href=\"" . $flickrvalue['link'] . "\">" . $flickrvalue['title'] . "</a></h3>\n";
echo "<p>" . $flickrvalue['description'] . "</p>\n";

$photosToDisplay = 5; //change this to the number of photos you want to display

for($p=0;$p<$photosToDisplay;$p++){
	echo "<a href=\"" . $flickritem[$p]['link'] . "\"><img src=\"" . $flickritem[$p]['media']['m'] . "\" /></a>\n";
}

echo "<p><a href=\"" . $flickrvalue['link'] . "\">View all my photos</p>\n";
?>

以上是关于PHP Flickr照片引入PHP JSON的主要内容,如果未能解决你的问题,请参考以下文章

PHP 照片库通过flickr API

PHP 根据主题获取大型flickr照片

Flickr图片拉入PHP JSON

使用 PHP、curl 解码从 Flickr API 返回的 json 字符串

iOS flickr 搜索照片 json 返回 nil

Flickr 照片管理器中的 JSON 警告