title: How can I get one photo for every Flickr tag by a specific user in one request?
body: <p>Basically what I am doing is generating a page of thumbnails. There is one thumbnail for each tag that the specified user has. So if the user has used 50 different tags there will be 50 thumbnails (I'll eventually paginate this.). It works; it's just inefficient. Even with just 8 tags, this is very slow since it has to wait for 9 responses (+1 for the list of tags) from the Flickr servers. Is there a more efficient way to do this? I can't seem to find a better solution whilst scanning the Flickr APIs. Below is what I am currently using to do this.</p>
  
  <pre><code>&lt;?php   
      function get_api_url($additional_params) {
          $params = array_merge($additional_params, array(
              'api_key'   =&gt; API_KEY,
              'format'    =&gt; 'php_serial',
              'user_id'   =&gt; USER_ID,
          ));
  
          $encoded_params = array();
          foreach ($params as $k =&gt; $v)
              $encoded_params[] = urlencode($k) . '=' . urlencode($v);
  
          return 'http://api.flickr.com/services/rest/?' . implode('&amp;', $encoded_params);
      }
  
      // Set any additional paramaters.
      $additional_params = array(
          'method'    =&gt; 'flickr.tags.getListUser',
      );
  
      // Get the tags.
      $rsp_obj = unserialize(file_get_contents(get_api_url($additional_params))); 
  
      // Parse the tags.
      $unparsed_tags = $rsp_obj['who']['tags']['tag'];
      $tags = array();
      foreach ($unparsed_tags as $tag) {
          $tags[] = $tag['_content'];
      }
  
      // Set any additional parameters.
      $additional_params = array(
          'method'    =&gt; 'flickr.photos.search',
          'per_page'  =&gt; '1',
      );
      $api_url = get_api_url($additional_params);
  
      // Call the API and parse the response.
      echo "&lt;div id=\"tags\"&gt;";
      foreach ($tags as $tag) {
          $rsp_obj = unserialize(file_get_contents($api_url . '&amp;tags=' . urlencode($tag)));
          $photo = $rsp_obj['photos']['photo'][0];
  
          $image_url = 'http://farm' . $photo['farm'] . '.static.flickr.com/' .
              $photo['server'] . '/' . $photo['id'] . '_' . $photo['secret'] . '_m.jpg';
          $tag_url = "/gallery/?tag=$tag";
          $tag = ucwords($tag);
          echo &lt;&lt;&lt;HD
              &lt;a class="tag" href="$tag_url"&gt;
                  &lt;img src="$image_url" /&gt;
                  &lt;span class="caption"&gt;$tag&lt;/span&gt;
              &lt;/a&gt;
  HD;
      }
      echo '&lt;/div&gt;';
  
  ?&gt;
  </code></pre>