Skip to content

Instantly share code, notes, and snippets.

@h2rd
Forked from alright/gist:1698905
Created January 29, 2012 17:55
Show Gist options
  • Save h2rd/1699842 to your computer and use it in GitHub Desktop.
Save h2rd/1699842 to your computer and use it in GitHub Desktop.
Vkontakte API class
<?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