private function process_request($request) { global $API_DOMAIN, $API_DOMAIN_DOT_SUFFIX; $app_id = $this->app_id; $method = $request['method']; $callback = false; $serialized_result = ''; // Initialize result $result = array(); // Fix method name if (starts_with($method, $API_DOMAIN . '.')) { $method = substr($method, 9); } // Replace periods with underscores in method name $method_underscore = str_replace('.', '_', $method); $ec = $this->check_throttle($method_underscore, $request); if ($ec !== API_EC_SUCCESS) { $msg = $api_error_descriptions[$ec]; if ($ec === API_EC_BAD_IP) { $msg .= ' (ip was: ' . $_SERVER['REMOTE_ADDR'] . ')'; } throw new api10_FacebookApiException(array('error_code' => $ec, 'error_msg' => $msg)); } $impl = new FacebookApi10Implementation($app_id, $this->user_id, $this->session_key, $this->format); $api = new FacebookApi10Rest($impl); // Check that the method is valid if (!method_exists($api, $method_underscore) || !method_exists($impl, $method_underscore) || !api_can_call_method($app_id, $method_underscore)) { $ec = api10_FacebookApiErrorCode::API_EC_METHOD; throw new api10_FacebookApiException(array('error_code' => $ec, 'error_msg' => $GLOBALS['api_error_descriptions'][$ec])); } else { // Call the method and catch any exceptions $result = $api->{$method_underscore}($request); } switch ($this->format) { case 'manual': print api_xml_render_manual_error($ec, $msg, $request); break; case 'xml': // Prepare the XML response $xml_memory = xmlwriter_open_memory(); xmlwriter_set_indent($xml_memory, true); xmlwriter_set_indent_string($xml_memory, ' '); xmlwriter_start_document($xml_memory, API_VERSION_10, 'UTF-8'); if ($result instanceof Exception) { $name = 'error_response'; } else { $name = $method_underscore . '_response'; } $attrs = array(); // FBOPEN:NOTE here, if you are not publishing your own .xsd, to use 'facebook.com' instead // of $API_DOMAIN_DOT_SUFFIX $attrs['xmlns'] = 'http://api.' . $API_DOMAIN_DOT_SUFFIX . '/' . API_VERSION_10 . '/'; $attrs['xmlns:xsi'] = 'http://www.w3.org/2001/XMLSchema-instance'; if ($method_underscore != 'fql_query') { $attrs['xsi:schemaLocation'] = 'http://api.' . $API_DOMAIN_DOT_SUFFIX . '/' . API_VERSION_10 . '/ http://api.' . $API_DOMAIN_DOT_SUFFIX . '/' . API_VERSION_10 . '/facebook.xsd'; } if (is_array($result) && isset($result[0]) && $result[0] instanceof xml_element) { $attrs['list'] = 'true'; api_xml3_render_object($xml_memory, new xml_element($name, $result, $attrs)); } else { api_xml2_render_object($xml_memory, $name, $result, $attrs); } xmlwriter_end_document($xml_memory); // Write XML response $xml = xmlwriter_output_memory($xml_memory, true); if ($callback) { $xml = addslashes($xml); $xml = str_replace("\n", '\\n', $xml); $serialized_result = $callback . '(\'' . $xml . '\');'; } else { $serialized_result = $xml; } break; case 'json': $json = api_json2_render_object($result); if ($callback) { $serialized_result = $callback . '(' . $json . ');'; } else { $serialized_result = $json; } break; } return $serialized_result; }
$msg = $api_error_descriptions[$ec]; if ($ec === API_EC_BAD_IP) { $msg .= ' (ip was: ' . $_SERVER['REMOTE_ADDR'] . ')'; } throw new api10_FacebookApiException(array('error_code' => $ec, 'error_msg' => $msg)); } // Create API handler switch ($version) { case API_VERSION_10: default: $impl = new FacebookApi10Implementation($app_id, $user_id, $req_session_key, $format, $use_session_secret); $api = new FacebookApi10Rest($impl); break; } // Check that the method is valid if (!method_exists($api, $method_underscore) || !method_exists($impl, $method_underscore) || !api_can_call_method($app_id, $method_underscore, $use_session_secret)) { $ec = api10_FacebookApiErrorCode::API_EC_METHOD; throw new api10_FacebookApiException(array('error_code' => $ec, 'error_msg' => $api_error_descriptions[$ec])); } else { // Call the method and catch any exceptions $result = $api->{$method_underscore}($request); } } catch (api10_FacebookApiException $fax) { if ($fax instanceof FacebookFQLException && $method_underscore != 'fql_query') { $ec = api10_FacebookApiErrorCode::API_EC_PARAM; $fax = new api10_FacebookApiException(array('error_code' => $ec, 'error_msg' => $api_error_descriptions[$ec])); } $ec = $fax->error_code; $result = $fax; $args = array(); foreach ($request as $key => $val) {