Upload video to Youtube using Youtube API V3 and PHP(使用 Youtube API V3 和 PHP 将视频上传到 Youtube)
问题描述
我正在尝试使用 PHP 将视频上传到 Youtube.我正在使用 Youtube API v3,并且我正在使用 Google API PHP 客户端库的最新签出源代码.
我正在使用
上给出的示例代码https://code.google.com/p/google-api-php-client/ 执行身份验证.身份验证正常,但是当我尝试上传视频时,我得到 Google_ServiceException
错误代码为 500,消息为空.
I am trying to upload a video to Youtube using PHP. I am using Youtube API v3 and I am using the latest checked out source code of Google API PHP Client library.
I am using the sample code given on
https://code.google.com/p/google-api-php-client/ to perform the authentication. The authentication goes through fine but when I try to upload a video I get Google_ServiceException
with error code 500 and message as null.
我查看了之前提出的以下问题:使用php客户端库v3上传视频到youtube 但是接受的答案没有描述如何指定要上传的文件数据.
我发现了另一个类似的问题 Uploading file with Youtube API v3 and PHP,在评论中提到 categoryId 是强制性的,因此我尝试在代码段中设置 categoryId 但仍然给出相同的异常.
I had a look at the following question asked earlier:
Upload video to youtube using php client library v3 But the accepted answer doesn't describe how to specify file data to be uploaded.
I found another similar question Uploading file with Youtube API v3 and PHP, where in the comment it is mentioned that categoryId is mandatory, hence I tried setting the categoryId in the snippet but still it gives the same exception.
我还参考了文档网站上的 Python 代码(https:///developers.google.com/youtube/v3/docs/videos/insert ),但我在客户端库中找不到函数 next_chunk .但是我尝试放置一个循环(在代码片段中提到)以重试获取错误代码 500,但在所有 10 次迭代中我都得到了相同的错误.
I also referred to the Python code on the the documentation site ( https://developers.google.com/youtube/v3/docs/videos/insert ), but I couldn't find the function next_chunk in the client library. But I tried to put a loop (mentioned in the code snippet) to retry on getting error code 500, but in all 10 iterations I get the same error.
以下是我正在尝试的代码片段:
Following is the code snippet I am trying:
是不是我做错了什么?
推荐答案
我能够使用以下代码进行上传:
I was able to get the upload working using the following code:
这篇关于使用 Youtube API V3 和 PHP 将视频上传到 Youtube的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!