zax2002

Simple VK API Class

Dec 20th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. <?php
  2. class VK {
  3.     private $token;
  4.     private $v;
  5.    
  6.     const URL = 'https://api.vk.com/method/';
  7.    
  8.     public function __construct($token, $v = '5.69') {
  9.         $this->token = $token;
  10.         $this->v = $v;
  11.     }
  12.    
  13.     public function api($method, $params = array(), $obj = false) {
  14.         if(!array_key_exists('access_token', $params)) $params['access_token'] = $this->token;
  15.         if(!array_key_exists('v', $params)) $params['v'] = $this->v;
  16.        
  17.         $ch = curl_init(self::URL.$method);
  18.        
  19.         curl_setopt_array($ch, array(
  20.             CURLOPT_RETURNTRANSFER => true,
  21.             CURLOPT_POST => true,
  22.             CURLOPT_POSTFIELDS => $params
  23.         ));
  24.        
  25.         $resp = curl_exec($ch);
  26.         curl_close($ch);
  27.        
  28.         return json_decode($resp, !$obj);
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment