Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function api($method, $params = array()) {
- $token = $_SESSION["token"];
- $paramstr = http_build_query($params);
- $url = "https://api.vk.com/method/" . $method . "?" . $paramstr . "&access_token=" . $token;
- echo "query url: " . $url . "<br />\n";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_URL, $url);
- $data = curl_exec($ch);
- echo "response:<br />\n" . $data . "<br /><br />\n";
- curl_close($ch);
- return json_decode($data);
- }
- session_start();
- if (!isset($_SESSION["token"]))
- header('Location: http://api.vk.com/oauth/authorize?client_id=2642786&scope=audio&redirect_uri=http://home.makarushin.ru/apitest/auth_audio.php&response_type=code');
- if ($_SERVER["REQUEST_METHOD"]=="POST") {
- $r = api("audio.getUploadServer");
- $ch = curl_init($r->response->upload_url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_VERBOSE, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => "@test.mp3"));
- curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
- $audio = json_decode(curl_exec($ch));
- curl_close($ch);
- var_dump($audio);
- $r = api("audio.save", array(
- "server" => $audio->server,
- "audio" => $audio->audio,
- "hash" => $audio->hash
- ));
- }
- ?>
- <html>
- <head>
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <title>API test</title>
- </head>
- <body>
- <form method="post">
- <input type="submit" value="test" />
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement