2007年11月14日 星期三

Flicker API: search and extract tags

Sample code:
require_once("phpFlickr.php");
$f = new phpFlickr("api_key");

echo "--------------photos_search----------------
";
$search_args = array("text"=>"sunset","sort"=>"relevance");
$search_info = $f->photos_search($search_args);
$i = 1;
foreach ($search_info['photo'] as $photo)
{
$owner = $f->people_getInfo($photo['owner']);
$photo = $f->photos_getInfo($photo['id']);
echo "photo_id: ".$photo['id']."
";
echo "title: ".$photo['title']."
";
echo "tag[0]: ".$photo['tags']['tag'][0]['raw']."
";
if($i==3) break; $i++;
}
echo "==========================================";


Readme for search function:
/* This function strays from the method of arguments that I've
* used in the other functions for the fact that there are just
* so many arguments to this API method. What you'll need to do
* is pass an associative array to the function containing the
* arguments you want to pass to the API. For example:
* $photos = $f->photos_search(array("tags"=>"brown,cow", "tag_mode"=>"any"));
* This will return photos tagged with either "brown" or "cow"
* or both. See the API documentation (link below) for a full
* list of arguments.
*/

References:
http://flickr.com/services/api/

沒有留言: