"Ololo", CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false )); $vk_redirect_uri = 'http://zhumarin.ru/api_test/vk.php'; if (!isset($_GET['code'])) { $oauth_url = url( 'https://oauth.vk.com/authorize', array( 'client_id' => VK_APP_ID, 'scope' => 'notify friends photos audio video docs notes pages status offers questions groups notifications stats ads offline nohttps', 'display' => '', 'response_type' => 'code', 'redirect_uri' => $vk_redirect_uri ) ); header("Location: ".$oauth_url); } else { $res = request($ch, 'https://oauth.vk.com/access_token', array( 'client_id' => VK_APP_ID, 'client_secret' => VK_APP_SECRET, 'grant_type' => 'authorization_code', 'code' => $_GET['code'], 'redirect_uri' => $vk_redirect_uri )); $data = json_decode($res, true); if (is_array($data) && isset($data['access_token'])) { var_export($data); } else { echo 'Error:
'.htmlspecialchars($res).'
'; } } function url($path, $args, $html = false) { $url = $path.'?'.http_build_query($args, '', '&'); return $html ? htmlspecialchars($url) : $url; } function request($ch, $url, $data = array()) { curl_setopt($ch, CURLOPT_URL, $url); if ($data) { curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($ch, CURLOPT_POST, true); } $data = curl_exec($ch); curl_setopt($ch, CURLOPT_POST, false); return $data; }