Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- putenv("GOOGLE_APPLICATION_CREDENTIALS=" . CLIENT_ACCOUNT_FILE);
- $client = new Google_Client();
- $client->useApplicationDefaultCredentials();
- $client->setScopes(['https://www.googleapis.com/auth/youtube']);
- $client->setDefer(true);
- $youtube = new Google_Service_YouTube($client);
- try {
- $set_request = $youtube->thumbnails->set($video_id);
- $media = new Google_Http_MediaFileUpload(
- $client,
- $set_request,
- IMAGE_MIME,
- null,
- true,
- CHUNK_SIZE_BYTES
- );
- $media->setFileSize(filesize($image_path));
- $status = false;
- $handle = fopen($image_path, "rb");
- while (!$status && !feof($handle)) {
- $chunk = fread($handle, CHUNK_SIZE_BYTES);
- $status = $media->nextChunk($chunk);
- }
- fclose($handle);
- } catch (Exception $e) {
- echo "ERROR -> " . $e->getMessage();
- }
- $client->setDefer(false);
- {
- "error": {
- "errors": [
- {
- "domain": "youtube.thumbnail",
- "reason": "forbidden",
- "message": "The thumbnail cant be set for the specified video. The request might not be properly authorized.",
- "locationType": "parameter",
- "location": "videoId"
- }
- ],
- "code": 403,
- "message": "The thumbnail cant be set for the specified video. The request might not be properly authorized."
- }
- }
Add Comment
Please, Sign In to add comment