topical media & game development

talk show tell print

mashup-delicious-11-autobookmarkers-flickr.php / php



  <?php
  //bring in Snoopy.class.php (from Magpie’s extlib dir)
  require_once('lib/extlib/Snoopy.class.inc');
  snoopy = new Snoopy();
  
  //delicious mashups libarary - set your username and password please!
  define('DELICIOUS_USERNAME','username');
  define('DELICIOUS_PASSWORD','password');
  
  //bring in delicious_mashups.inc.php
  require_once('lib/delicious_mashups.inc.php');
  
  //flickr api key and shared secret
  define('API_KEY','apikey');
  define('SHARED_SECRET','sharedsecret');
  
  //this should be the user auth token you got from flickr_get_token.php
  define('FULL_TOKEN','fulltoken');
  
  //calculate api_sig for flickr.favorites.getList
  api_sig = 
  md5(SHARED_SECRET."api_key".API_KEY."auth_token"
      .FULL_TOKEN."methodflickr.favorites.getList");
  
  snoopy->fetch("http://www.flickr.com/services/rest/?method=flickr.favorites.getList&api_key=".API_KEY."&auth_token=".FULL_TOKEN."&api_sig=".api_sig);
  
  parse_xml_results(snoopy->results);
  
  //take what we now need from api_return because our del.icio.us call will
  //unset it later
  photos = api_return[0]['children'][0]['children'];
  
  //go through each photo and save if never saved to del.icio.us before
  foreach (photos as photo)
  {
      url = 
  sprintf("http://www.flickr.com/photos/%s/%s",photo['attributes']['OWNER'],
  photo['attributes']['ID']);
      description = photo['attributes']['TITLE'];
      tags = "flickr photography autobookmarked";
      //check to see if the url has already been posted
      do_api_call('/posts/get?',"&url=".urlencode(url));
      if (!isset(api_return[0]['children']))
      {
       do_api_call('/posts/add?',"&url=".urlencode(url)."&description="
       .urlencode(description)."&tags=".urlencode(tags));
          if (api_return['status'] == 200)
              echo "Posted: ".description."\n";
          else
              echo "There was a problem posting ".description."\n";
      } else {
          echo url." already posted - skipping\n";
      }
  }
  
  ?>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.