Impossible de définir un filigrane à travers YouTube API à l'aide de la bibliothèque cliente Google PHP

StackOverflow https://stackoverflow.com//questions/21004169

Question

J'utilise la nouvelle bibliothèque client de Google API PHP de GITUB.Voici le code:

$client = new Google_Client();
$client->setClientId( 'CLIENTID' );
$client->setClientSecret( 'CLIENTSECRET' );
$client->refreshToken( 'REFRESHTOKEN' );
$youtube = new Google_Service_YouTube( $client );
$channelId = 'UC...';
$imagePath = "./image.jpeg";
$postBody = new Google_Service_YouTube_InvideoBranding();
$postBody->setImageBytes( filesize( $imagePath ) );
$postBody->setTargetChannelId( $channelId );
$imageData = file_get_contents( $imagePath );
$resource = array(
    'data' => $imageData,
    'mimeType' => 'image/jpeg,image/png,application/octet-stream',
    'uploadType' => 'media'
);
$youtube->watermarks->set( $channelId, $postBody, $resource );

Mais j'ai eu l'exception suivante:

PHP Warning:  file_get_contents(/upload/youtube/v3/watermarks/set?channelId=UC...&uploadType=multipart): failed to open stream: No such file or directory in ....../src/Google/IO/Stream.php on line 109
PHP Fatal error:  Uncaught exception 'Google_IO_Exception' with message 'HTTP Error: Unable to connect' in ....../src/Google/IO/Stream.php:112
Stack trace:
#0 ....../src/Google/Http/REST.php(46): Google_IO_Stream->makeRequest(Object(Google_Http_Request))
#1 ....../src/Google/Client.php(492): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request))
#2 ....../src/Google/Service/Resource.php(194): Google_Client->execute(Object(Google_Http_Request))
#3 ....../src/Google/Service/YouTube.php(2687): Google_Service_Resource->call('set', Array)
#4 .../watermark.php(48): Google_Service_YouTube_Watermarks_Resource->set('UC...', Object(Google_Service_YouTube_InvideoBranding), Array)
#5 {main}
  thrown in ....../src/Google/IO/Stream.php on line 112

Semblable à "Set thumbnail".Où est-ce que je fais mal?

Était-ce utile?

La solution

Essayez d'utiliser Google_HTTP_MEDIAFILEUPLOAD pour télécharger le fichier image.

Voici un exemple: https:// github.com / youtube / API-échantillons / blob / maître / php / upload_thumbnail.php # L78

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top