【问题标题】:Cannot set watermark thru YouTube API using Google PHP Client Library无法使用 Google PHP 客户端库通过 YouTube API 设置水印
【发布时间】:2014-01-08 18:54:57
【问题描述】:

我正在使用来自 GitHub 的新 Google API PHP 客户端库。代码如下:

$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 );

但我遇到了以下异常:

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

类似于“设置缩略图”。我哪里做错了?

【问题讨论】:

    标签: php youtube youtube-api google-api-php-client


    【解决方案1】:

    尝试使用 Google_Http_MediaFileUpload 上传图片文件。

    这是一个例子:https://github.com/youtube/api-samples/blob/master/php/upload_thumbnail.php#L78

    【讨论】:

    • 我按照示例进行了操作,但仍然出现“HTTP 错误:无法连接”异常。
    • 这是一个错误吗?它调用file_get_contents(/upload/youtube/v3/thumbnails/set...) 而不是file_get_contents(https://www.googleapis.com/upload/...)
    • 我在客户端库中添加了https://www.googleapis.com,它似乎正在运行,但我得到了“禁止”异常。我使用客户端库和相同的身份验证编辑视频元数据没有问题。
    • 似乎最新的提交修复了这个错误。但我得到了PHP Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling PUT https://www.googleapis.com/upload/youtube/v3/thumbnails/set?videoId=...&uploadType=resumable&upload_id=AEn...: (403) Forbidden' in ....../src/Google/Http/REST.php:74 Stack trace: #0 ....../src/Google/Http/MediaFileUpload.php(162): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request)) #1 ....../....php(66): Google_Http_MediaFileUpload->nextChunk('??????JFIF?????...') #2 {main} thrown in ....../src/Google/Http/REST.php on line 74
    • 您可以查看youtube.com/features 以查看您的帐户是否有资格使用自定义缩略图。您的帐户需要经过验证并且信誉良好。
    猜你喜欢
    • 2015-06-13
    • 2018-03-22
    • 2013-11-08
    • 1970-01-01
    • 1970-01-01
    • 2015-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多