Recent Changes - Search:

Distributed Computing

This website demonstrates using wikis as teaching and learning tool.

The course instructor is also happy to share the teaching materials here with those who find it readable.

Access Web Services with PHP

Activity

Study the following PHP script. Answer the questions that follow. You can discuss the questions with your classmates.

<?php

$api_service_url = "http://search.yahooapis.com/SiteExplorerService/V1/inlinkData";
$apiid = "pQzlchXV34GhgyFFcNhE8ijvqemS0pw4G3VIf1fLyspIx.9Cg5cRIU1ESXNHD9c6BXXZ";
$query  = "http://www.stevenchoy.com";
$entire_site  = "";   // "1" to provide results for the entire site
$omit_inlinks = "domain";
$linksperrequest = 10;   // 100 is max value
$startposition = 1;

$request_url = sprintf("%s?appid=%s&query=%s&entire_site=%s&omit_inlinks=%s&output=php", $api_service_url, $apiid, urlencode($query), $entire_site, $omit_inlinks);

$currentpos = 0;
while ($currentpos++ >= 0) {

   // Formating API request url
   $requrl = sprintf("%s&start=%s&results=%s", $request_url, ($currentpos-1)*$linksperrequest+$startposition, $linksperrequest);

   // Handle errors
   if (($content = file_get_contents($requrl)) === FALSE ) {
   echo "HTTP error: $requrl
"
;
   exit;
   }

   // Unserialize data from response
   $data = unserialize($content);

   if (!array_key_exists("ResultSet", $data)) {
   echo "Error: Bad response from server
"
;
   exit;
   }

   // Extracting each link from array
   for ($i=0; $i<sizeof($data["ResultSet"]["Result"]); $i++) {
      $url = $data["ResultSet"]["Result"][$i]["Url"];
      $title = $data["ResultSet"]["Result"][$i]["Title"];

      echo '<p><a href="'.$url.'">'.$title.'</a></p>';


   }

   // End loop if no more results
   if (sizeof($data["ResultSet"]["Result"]) < $linksperrequest) break;
}

?>

(The API key shown in the PHP script is not a real one. Please obtain and use your own API key if you want to test the program in your server.)

Questions

  1. What type of Web Services that the program accesses? Explain your answer.
  2. Figure out the particular web service that the program accesses.
  3. Figure out the function of the program.
  4. Can you use a Java program to implement the function of the program. Explain your answer.
Edit - History - Print - Recent Changes - Search
Page last modified on November 14, 2007, at 09:46 AM