-
-
Save h2rd/1699842 to your computer and use it in GitHub Desktop.
Vkontakte API class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Vkapi { | |
protected $_access_token = '%access_token%'; | |
protected $_client_id = 0; | |
public static function factory () | |
{ | |
$class = get_class(); | |
return new $class; | |
} | |
public function method ($method, array $params = array()) | |
{ | |
$params['access_token'] = $this->_access_token; | |
$url = 'https://api.vkontakte.ru/method/'.$method.'?'.http_build_query($params); | |
$content = file_get_contents($url); | |
$result = json_decode($content); | |
$result = $result->response; | |
if ($result === NULL) | |
{ | |
throw new Exception('Some error with VK API'); | |
} | |
return $result; | |
} | |
public function auth (array $scopes = array()) | |
{ | |
if (count($scopes) <= 0) | |
{ | |
$scopes = array('offline', 'video', 'wall'); | |
} | |
header('Content-type: text/html; charset=windows-1251'); | |
$url_scopes = implode(',', $scopes); | |
echo file_get_contents('http://oauth.vkontakte.ru/authorize?client_id='.$this->_client_id.'&scope='.$url_scopes.'&redirect_uri=http://api.vkontakte.ru/blank.html&display=page&response_type=token'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment