Posted By

stephanepericat on 12/14/09


Tagged

curl php delicious simplexml


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

xmartyxcorex
spf13
gemmes
jackkeller
techdetours


Delicious query function


 / Published in: PHP
 

an easy-to-use function to connect to your del.icio.us account and perform a query. query commands can be found on their api help: http://delicious.com/help/api

  1. <?php
  2.  
  3. /**
  4.  * Delicious_query();
  5.  * @author: Stephane P. Pericat
  6.  * @date: 2009-12-14
  7.  *
  8.  * @param : $credentials(array), $request(string)
  9.  * @return: simpleXML object
  10.  */
  11. function delicious_query($credentials = array(), $request) {
  12. if(empty($credentials)) {
  13. throw new InvalidArgumentException("no credentials provided");
  14. }
  15.  
  16. $username = $credentials["username"];
  17. $password = $credentials["password"];
  18. $base_url = "https://".$username.":".$password."@api.del.icio.us/v1/";
  19. $full_url = $base_url.$request;
  20.  
  21. $ch = curl_init($full_url);
  22. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  23. $query = curl_exec($ch);
  24. curl_close($ch);
  25.  
  26. return simplexml_load_string($query);
  27. }
  28.  
  29. $creds = array("username" => "your_username",
  30. "password" => "your_password");
  31.  
  32. $query = delicious_query($creds, "posts/all?tag=php");
  33. var_dump($query);

Report this snippet  

You need to login to post a comment.