Flickr API - flickr.photos.search

Posted on 2009-02-22
Medium Priority
Last Modified: 2012-05-06
Hi, I want to show photos in my page from flickr.
I get the API key, and I going to one page that show the arguments of the method 'flickr.photos.search' (http://www.flickr.com/services/api/explore/).
When I call the method the system give me this results:
  <?xml version="1.0" encoding="utf-8" ?>
- <rsp stat="ok">
- <photos page="1" pages="409880" perpage="5" total="2049400">
  <photo id="3299837581" owner="13605215@N03" secret="7e419a7e7f" server="3463" farm="4" title="Labradors" ispublic="1" isfriend="0" isfamily="0" />
  <photo id="3299833035" owner="13605215@N03" secret="68220f9825" server="3618" farm="4" title="American Rottweiler" ispublic="1" isfriend="0" isfamily="0" />
  <photo id="3299828965" owner="13605215@N03" secret="0b0a4283fa" server="3624" farm="4" title="German Rottweiler" ispublic="1" isfriend="0" isfamily="0" />
  <photo id="3299818615" owner="57838910@N00" secret="1be93d9069" server="3470" farm="4" title="Sophia" ispublic="1" isfriend="0" isfamily="0" />
  <photo id="3299795245" owner="35052628@N00" secret="1a842d13bd" server="3517" farm="4" title="Layla lookin TOUGH" ispublic="1" isfriend="0" isfamily="0" />
and give me this URL: http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=d0f7080bde89b249787cc6a2e9e196f4&tags=dogs%2C+cats&privacy_filter=1&per_page=5&auth_token=72157614297072820-bb2ba17aa84a0161&api_sig=58929a7e6d65a1fc0e174bb5873d2775
If I want to show that 5 photos about dogs and cats in php, how I do?
Regards, JC  
Question by:Pedro Chagas
  • 4
  • 3
LVL 19

Accepted Solution

v2Media earned 1500 total points
ID: 23705707

Author Comment

by:Pedro Chagas
ID: 23709835
hi, i see the example in the page you send to me.
i have one doubt, where i get the file phpFlickr.php or what i put inside of the file.
regards, jc
LVL 19

Expert Comment

ID: 23709923
phpFlickr.php is available for download at flickr, as linked in the example page given. All the source code is there to tinker with.

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

by:Pedro Chagas
ID: 23715327
I do the download and I install PEAR module of flickr in my server. I create a folder that contain entire files of the download, the folder call "phpFlickr", because in example have this line require_once("phpFlickr/phpFlickr.php");

Have one file that call auth.php, and I put inside my keys of flickr.
I try to execute index.php (view code snippet), and I get this phrase:
"DB Error: connect failed".

I need a database? For what?
I don't want photos from a username, I want get photos from a search (flickr.photos.search).

What is the next step?

Regards, JC
// Create new phpFlickr object
$f = new phpFlickr("[API Key]");
$i = 0;
if (!empty($_POST['username'])) {
    // Find the NSID of the username inputted via the form
    $person = $f->people_findByUsername($_POST['username']);
    // Get the friendly URL of the user's photos
    $photos_url = $f->urls_getUserPhotos($person['id']);
    // Get the user's first 36 public photos
    $photos = $f->people_getPublicPhotos($person['id'], NULL, 36);
    // Loop through the photos and output the html
    foreach ((array)$photos['photos']['photo'] as $photo) {
        echo "<a href=$photos_url$photo[id]>";
        echo "<img border='0' alt='$photo[title]' ". //>
            "src='" . $f->buildPhotoURL($photo, "Square") . "' />";
        echo "</a>";
        // If it reaches the sixth photo, insert a line break
        if ($i % 6 == 0) {
            echo "<br />n";
<h3>Enter a username to search for</h3>
<form method='post'>
    <input name='username'/><br />
    <input type='submit' value='Display Photos'/>

Open in new window

LVL 19

Expert Comment

ID: 23716635
"I want to show photos in my page from flickr"
"I don't want photos from a username, I want get photos from a search"

So which is it? In the original question you wanted to display images from your flickr page. Now you want to search flickr?

Your other questions are answered in the comments of the source code. You need to store the resulting images in EITHER a database or the file system.

After your last post, it's obvious that you want to do up a flickr search engine. The api is not going to help you there. Even the search method in the flickr object requires you to state which flickr user account/s to search.

Author Comment

by:Pedro Chagas
ID: 23716780
Hi, In the title of this question I put 'flickr.photos.search', and I thing this is the method for do what I want, if isn't, I'm sorry about my ignorance.

What I want not is a pure search engine, but something like.
I develop a project, and the objective of this project is you write a 'title' in the box, like: "The best print paper", and the system go check the web (between 1 -  2 minutes), and the result is a report about "The best print paper", I give you the best title I found in the NET, the words more write in all web sites I check, I give information about some important html tags, and so on.
So, if you see one, just one report, you like, but after 10.000 reports (or 10.000 titles) it's always words, seems like the same thing for 10.000 results.
So I thing, I go put more beauty things in each report, and image helps. I want give 3 or 4 photos about the+best+print+paper or another title customer search. In this way I produce more beautiful reports pages, and not seems the same thing.

Do you thing this is the write way to put my reports most different? Have another solution (if it is impossible in flickr)?

The best regards, JC
LVL 19

Assisted Solution

v2Media earned 1500 total points
ID: 23721898
Even if it's possible, I don't think it's legal. You're using flickr as a source of image information in an automated information retrieval system. Typically this is expressly forbidden in copyrighted materials. You'd have to read the terms and conditions to find out if it's legal before going to all the trouble of making it possible.

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question