Advertisement
makapoh

Untitled

Mar 14th, 2016
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. <?php
  2. $token = "..."; // тут токен
  3.  
  4. function vk($method, $params = array()) {
  5. global $token;
  6. $paramstr = http_build_query($params);
  7. $url = "https://api.vk.com/method/" . $method . "?" . $paramstr . "&v=5.27&access_token=" . $token;
  8. $ch = curl_init();
  9. curl_setopt($ch, CURLOPT_HEADER, 0);
  10. curl_setopt($ch, CURLOPT_VERBOSE, 0);
  11. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  12. curl_setopt($ch, CURLOPT_URL, $url);
  13. $r = json_decode(curl_exec($ch));
  14. curl_close($ch);
  15. return $r;
  16. }
  17.  
  18. $file = "test.mp3";
  19. $r = vk("audio.getUploadServer");
  20. var_dump($r);
  21. $ch = curl_init($r->response->upload_url);
  22. curl_setopt($ch, CURLOPT_HEADER, 0);
  23. curl_setopt($ch, CURLOPT_VERBOSE, 0);
  24. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  25. curl_setopt($ch, CURLOPT_POST, true);
  26. curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => "@test.mp3"));
  27. $r = json_decode(curl_exec($ch));
  28. var_dump($r);
  29. curl_close($ch);
  30.  
  31. $r = vk("audio.save", array(
  32. "server" => $r->server,
  33. "audio" => $r->audio,
  34. "hash" => $r->hash,
  35. "artist" => "test artist",
  36. "title" => "test title"
  37. ));
  38. var_dump($r);
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement