YouTube PHP API - 获取先前上传视频的状态?

发布于 2024-12-06 19:14:29 字数 1031 浏览 1 评论 0原文

刚刚开始深入研究 YouTube PHP API 并让基于浏览器的 Zend 上传脚本正常工作。但是,我找不到任何有关如何在上传视频后检索视频状态的文档。我需要这个的主要原因是为了错误处理 - 我需要能够知道该视频是否得到 YouTube 的批准,因为有人可能在技术上上传太大的图像或文件。我需要知道该视频已获得批准,以便我知道最终用户返回网站时要显示什么消息(即“您的视频已上线”或“视频上传失败”)。

基于 YouTube PHP 浏览器的上传即使格式或大小不正确也会返回 200 的 URL 参数状态,这当然没有帮助。关于如何从 YT 对象获取此信息的任何想法?

总而言之,当用户返回网站时,我希望能够根据他们的特定视频 ID 创建一个 YT 对象,并希望能够确认它没有被拒绝。我正在使用 ClientLogin 启动 YouTube 对象:

$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
              $username = '[email protected]',
              $password = 'mypassword',
              $service = 'youtube',
              $client = null,
              $source = 'MySource', // a short string identifying your application
              $loginToken = null,
              $loginCaptcha = null,
              $authenticationURL);

有什么想法吗?

Just started digging into the YouTube PHP API and got the browser-based Zend upload script working. However, I can't find any documentation on how to retrieve the status of the video after it's been uploaded. The main reason I would need this is for error handling - I need to be able to know whether the video was approved by YouTube, since someone could technically upload an image or a file too large. I need to know that the vid was approved so that I know what message to display the end user when they return to the site (ie 'Your video is live' or 'Video upload failed').

The YouTube PHP browser-based upload returns a URL parameter status of 200 even if the format or size is incorrect, which is of course not helpful. Any ideas on how else to get this info from the YT object?

All in all, when a user returns to the site, I want to be able to create a YT object based on their specific video ID, and want to be able to confirm that it was not rejected. I'm using ClientLogin to initiate the YouTube obj:

$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
              $username = '[email protected]',
              $password = 'mypassword',
              $service = 'youtube',
              $client = null,
              $source = 'MySource', // a short string identifying your application
              $loginToken = null,
              $loginCaptcha = null,
              $authenticationURL);

Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏至、离别 2024-12-13 19:14:29

哇,经过几天的搜索和拼凑代码,终于找到了这个问题的答案。创建 $yt 对象后,使用以下命令检查状态:

$yt->setMajorProtocolVersion(2);
$youtubeEntry = $yt->getVideoEntry('YOUR_YOUTUBE_VID_ID', null, true);

if ($youtubeEntry->getControl()){
    $control = $youtubeEntry->getControl();
    $state = $control->getState()->getName();
}

如果视频播放失败,则回显 $state 将显示字符串 'failed'无论出于何种原因未获批准。否则它是空的,这意味着它已获得批准并且可以继续使用(猜测其他状态名称将是:处理、拒绝、失败、限制,如 Mient-jan Stelling 上面建议的那样)。

对于第一次使用 YouTube API 的人来说,要给出这个答案是多么困难。解决了! (拍拍自己的背)

Whew, finally found the answer to this after searching around and piecing together code for the last few days. After you create the $yt object, use the following to check the status:

$yt->setMajorProtocolVersion(2);
$youtubeEntry = $yt->getVideoEntry('YOUR_YOUTUBE_VID_ID', null, true);

if ($youtubeEntry->getControl()){
    $control = $youtubeEntry->getControl();
    $state = $control->getState()->getName();
}

Echoing out $state displays the string 'failed' if the video was not approved for whatever reason. Otherwise it's empty, which means it was approved and is good to go (Guessing the other state names would be: processing, rejected, failed, restricted, as Mient-jan Stelling suggested above).

Crazy how tough this answer was to put together for first-time YouTube API'ers. Solved! (Pats self on back)

若水微香 2024-12-13 19:14:29

您有 CallToken吗?如果有的话,这很容易。

在本示例中,我使用 Zend_Gdata_Youtube 和 Zend AuthSub。

上传视频时,您有一个 CallToken,通过此呼叫令牌,您可以访问视频的状态。

$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
          $username = '[email protected]',
          $password = 'mypassword',
          $service = 'youtube',
          $client = null,
          $source = 'MySource', // a short string identifying your application
          $loginToken = null,
          $loginCaptcha = null,
          $authenticationURL);

$youtube = new Zend_Gdata_YouTube( $httpClient, '', NULL, YOUTUBE_DEVELOPER_KEY );

$youtubeEntry = $youtube->getFullVideoEntry( 'ID_OF_YOUTUBE_MOVIE' ); 
// its the 11 digit id all youtube video's have

在 $youtubeEntry 中,如果 state 为 null,则存在有关视频的所有数据

$state = $youtubeEntry->getVideoState();

,则您的视频可用,否则将 state 设为这样的字符串。

(string) $state->getName();

大约有 4 个重要的州名。 (处理、拒绝、失败、限制)

Do you have a CallToken if so its pretty easy.

For this example i use Zend_Gdata_Youtube with Zend AuthSub.

WHen uploading your video you had a CallToken, With this call token you can access the status of the video.

$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
          $username = '[email protected]',
          $password = 'mypassword',
          $service = 'youtube',
          $client = null,
          $source = 'MySource', // a short string identifying your application
          $loginToken = null,
          $loginCaptcha = null,
          $authenticationURL);

$youtube = new Zend_Gdata_YouTube( $httpClient, '', NULL, YOUTUBE_DEVELOPER_KEY );

$youtubeEntry = $youtube->getFullVideoEntry( 'ID_OF_YOUTUBE_MOVIE' ); 
// its the 11 digit id all youtube video's have

in $youtubeEntry all your data about the video is present

$state = $youtubeEntry->getVideoState();

if state is null then your video is available else make of state a string like this.

(string) $state->getName();

There are about 4 important state names. ( processing, rejected, failed, restricted)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文