Advertisement
Grumblerbear

VK client api

Aug 18th, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. class VK {
  2.     static $predefined_params;
  3.  
  4.     public static function init ($predefined_params) {
  5.         self::$predefined_params = $predefined_params;
  6.     }
  7.     public static function api ($method, $params) {
  8.         $params = array_merge(self::$predefined_params, $params);
  9.  
  10.         $ch = curl_init();
  11.         curl_setopt($ch, CURLOPT_URL, "https://api.vk.com/method/{$method}");
  12.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  13.         curl_setopt($ch, CURLOPT_POST, true);
  14.         curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  15.  
  16.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  17.         curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
  18.         $response_raw = curl_exec($ch);
  19.         curl_close($ch);
  20.  
  21.         $response = json_decode($response_raw, TRUE);
  22.         return $response;
  23.     }
  24. }
  25.  
  26. // example
  27. VK::init(array(
  28.     'access_token' => $_GET['access_token'],
  29.     'https' => 1,
  30.     'v' => '5.24',
  31. ));
  32. $response = VK::api("audio.get", array('owner_id' => $_GET['viewer_id']));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement