Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

auto approve application

  • Loading branch information...
commit 10c0f04695bc53de64068373afd20a6d7c9e6c2f 1 parent 69f2653
@m8rge authored
Showing with 38 additions and 1 deletion.
  1. +21 −0 CurlHelper.php
  2. +17 −1 VkClient.php
View
21 CurlHelper.php
@@ -10,7 +10,10 @@ static function getUrl($url, $additionalConfig = array()) {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt_array($ch, $additionalConfig);
$data = curl_exec($ch);
+ $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
+ if (in_array($http_status, array(400, 401, 403, 404, 500)))
+ throw new Exception("url $url return $http_status response code");
return $data;
}
@@ -25,8 +28,26 @@ static function postUrl($url, $postQuery, $additionalConfig = array()) {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt_array($ch, $additionalConfig);
$data = curl_exec($ch);
+ $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
+ if (in_array($http_status, array(400, 401, 403, 404, 500)))
+ throw new Exception("url $url return $http_status response code. postFields: ".print_r($postQuery, true));
return $data;
}
+
+ static function downloadToFile($url, $toFile, $additionalConfig = array()) {
+ $fp = fopen($toFile, 'w');
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_FILE, $fp);
+ curl_setopt_array($ch, $additionalConfig);
+ curl_exec($ch);
+ $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+ curl_close($ch);
+ fclose($fp);
+
+ if (in_array($http_status, array(400, 401, 403, 404, 500)))
+ throw new Exception("url $url return $http_status response code");
+ }
}
View
18 VkClient.php
@@ -12,7 +12,7 @@ class VkClient
* @param string $email Email used to login
* @param string $password Password used to login
* @param integer $scope Access rights bit mask
- * @param string $devNull URL to dummy file (used for redirect with access_token from vk servers)
+ * @param string $devNull URL to dummy html page
* @throws Exception
*/
function __construct($appId, $email, $password, $scope, $devNull)
@@ -50,6 +50,22 @@ function __construct($appId, $email, $password, $scope, $devNull)
if (preg_match('#access_token=(\w+)#', $loginData, $matches)) {
$this->accessToken = $matches[1];
return;
+ } elseif (preg_match('#onclick\s*=\s*"\s*return\s+allow\s*\(\s*\);?\s*"#', $loginData, $matches)) {
+ // we need approve application
+ if (!preg_match('#function\s+allow\s*\(\s*\)\s*{.*?"(https://[^"]+)"#s', $loginData, $matches))
+ throw new Exception('can\'t get access token');
+ $loginData = CurlHelper::getUrl($matches[1], array(
+ CURLOPT_HEADER => 1,
+ CURLOPT_FOLLOWLOCATION => 1,
+ CURLOPT_COOKIEJAR => $cookieFile,
+ CURLOPT_COOKIEFILE => $cookieFile,
+ ));
+ if (preg_match('#access_token=(\w+)#', $loginData, $matches)) {
+ $this->accessToken = $matches[1];
+ return;
+ }
+ } elseif ($phpQueryObject->find("$('form input[name=email]')")->count() == 1) {
+ throw new Exception('wrong login/password');
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.