21 private $accessToken = NULL;
22 public static $apiUrl =
'https://api.vk.com/method/';
37 $this->exportId = $exportId;
38 $this->response = array();
42 $this->accessToken = $accessToken;
57 public function run($method, $params = array())
59 $params[
'access_token'] = $this->accessToken;
60 $params[
'v'] = self::$apiVersion;
61 $url = self::$apiUrl . $method;
64 $responseStr = $http->post($url, $params);
66 if (!is_string($responseStr))
71 $this->response = Json::decode($responseStr);
72 $this->checkError($method, $params);
74 return $this->response[
'response'];
85 private function checkError($method, $params)
88 if ($this->checkRequestsLimit())
90 return $this->run($method, $params);
93 if (isset($this->response[
"error"]))
97 'Catch error in method ' . $method,
98 array(
'ERROR' => $this->response[
"error"] .
' - ' . $this->response[
"error_msg"],
"PARAMS" => $params)
100 $logger->addError($this->response[
"error"][
"error_code"], $method);
102 throw new Vk\ExecuteException(
"VK_critical_execution_error " . $this->response[
"error"][
"error_code"] .
" in method " . $method);
106 if (isset($this->response[
"execute_errors"]))
108 $logger =
new Vk\Logger($this->exportId);
109 foreach ($this->response[
"execute_errors"] as $er)
112 'Execute error in method ' . $method,
113 array(
'ERROR' => $er[
"error_code"] .
' (' . $er[
"method"] .
') - ' . $er[
"error_msg"],
"PARAMS" => $params,
114 "RESPONSE" => $this->response)
116 $logger->addError($er[
"error_code"]);
124 private function checkRequestsLimit()
127 if (isset($this->response[
"error"]) && $this->response[
"error"][
"error_code"] == self::TOO_MANY_REQUESTS_ERROR_CODE)
130 $this->response = array();
static loadMessages($file)