topical media & game development

talk show tell print

mashup-delicious-11-autobookmarkers-ebay.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');
  
  //ebay base rest api url (this is the sandbox! not live ebay)
  define('BASE_REST_URL','http://rest.api.sandbox.ebay.com/restapi');
  //ebay rest token and user_id
  define('USER_REST_TOKEN','resttoken');
  define('USER_ID','userid');
  
  //fetch query string from arguments
  if (!isset(argv[1]))
      die("You need to specify something to search for as an argument!\n");
  else
      search_string = urlencode(argv[1]);
  
  //full query url
  full_api_url = BASE_REST_URL."?CallName=GetSearchResults&RequestToken="
      .USER_REST_TOKEN."&RequestUserId=".USER_ID."&Query=".search_string;
  
  snoopy->fetch(full_api_url);
  
  parse_xml_results(snoopy->results);
  
  //search for the xml elements we need
  root_element_children = api_return[0]['children'];
  foreach (root_element_children as root_element_child)
  {
      if (root_element_child['name'] == "SEARCH") {
          search_items = root_element_child['children'];
          foreach (search_items as search_item)
          {
              if(search_item['name'] == "ITEMS") {
                  search_result_items = search_item['children'];
              }
              break;
          }
          break;
      }
  }
  
  foreach (search_result_items as search_result_item)
  {
      //determine the item title and url
      item_details = search_result_item['children'];
      foreach (item_details as item_detail)
      {
          if (item_detail['name'] == "LINK")
              url = item_detail['cdata'];
          if (item_detail['name'] == "TITLE")
              description = item_detail['cdata'];
      }
      unset(item_details);
      //check to see if the url has already been posted
      do_api_call('/posts/get?',"&url=".urlencode(url));
      if (!isset(api_return[0]['children']))
      {
          tags = "autobookmarked ebay";
          do_api_call('/posts/add?',"&url=".urlencode(url)."&description=".urlencode(description)."&extended=".urlencode(extended)."&tags=".urlencode(tags));
          if (api_return['status'] == 200)
              echo "Posted: ".description."\n";
          else
              echo "There was a problem posting ".description."\n";
      } else {
          echo item['link']." already posted - skipping\n";
      }
      //unset url and description
      unset(url);
      unset(description);
  }
  
  ?>
  


(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.