Flickr Search with curl


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. // build request format
  3. $xml = simplexml_load_string('<?xml version="1.0" ?><methodCall />');
  4. // method name
  5. $xml->addChild('methodName','flickr.photos.search');
  6. // parameters list
  7. $params = $xml->addChild('params',null)->addChild('param',null)->addChild('value',null)->addChild('struct',null);
  8. // add api key
  9. $child = $params->addChild('member',null);
  10. $child->addChild('name','api_key');
  11. $child->addChild('value','**key-value**');
  12. // add tag to search for
  13. $child = $params->addChild('member',null);
  14. $child->addChild('name','tags');
  15. $child->addChild('value','ibuildings');
  16.  
  17. // make request
  18. $url = 'http://api.flickr.com/services/xmlrpc/';
  19. $ch = curl_init($url);
  20. curl_setopt($ch, CURLOPT_POST, 1);
  21. curl_setopt($ch, CURLOPT_POSTFIELDS, $xml->asXML());
  22. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  23.  
  24. $response = curl_exec($ch);
  25. $response_xml = simplexml_load_string($response);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.