Guest User

Untitled

a guest
Nov 22nd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. putenv("GOOGLE_APPLICATION_CREDENTIALS=" . CLIENT_ACCOUNT_FILE);
  2.  
  3. $client = new Google_Client();
  4. $client->useApplicationDefaultCredentials();
  5. $client->setScopes(['https://www.googleapis.com/auth/youtube']);
  6. $client->setDefer(true);
  7.  
  8. $youtube = new Google_Service_YouTube($client);
  9. try {
  10. $set_request = $youtube->thumbnails->set($video_id);
  11. $media = new Google_Http_MediaFileUpload(
  12. $client,
  13. $set_request,
  14. IMAGE_MIME,
  15. null,
  16. true,
  17. CHUNK_SIZE_BYTES
  18. );
  19.  
  20. $media->setFileSize(filesize($image_path));
  21.  
  22. $status = false;
  23. $handle = fopen($image_path, "rb");
  24. while (!$status && !feof($handle)) {
  25. $chunk = fread($handle, CHUNK_SIZE_BYTES);
  26. $status = $media->nextChunk($chunk);
  27. }
  28. fclose($handle);
  29. } catch (Exception $e) {
  30. echo "ERROR -> " . $e->getMessage();
  31. }
  32. $client->setDefer(false);
  33.  
  34. {
  35. "error": {
  36. "errors": [
  37. {
  38. "domain": "youtube.thumbnail",
  39. "reason": "forbidden",
  40. "message": "The thumbnail cant be set for the specified video. The request might not be properly authorized.",
  41. "locationType": "parameter",
  42. "location": "videoId"
  43. }
  44. ],
  45. "code": 403,
  46. "message": "The thumbnail cant be set for the specified video. The request might not be properly authorized."
  47. }
  48. }
Add Comment
Please, Sign In to add comment