【问题标题】:How to get the Video-ID of a just uploaded Youtube movie如何获取刚刚上传的 Youtube 电影的 Video-ID
【发布时间】:2011-02-23 03:41:54
【问题描述】:

如何获取刚刚上传的 Youtube 电影的 video-id?

我正在使用此代码:

$yt = new Zend_Gdata_YouTube($httpClient);
// create a new Zend_Gdata_YouTube_VideoEntry object
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();

// create a new Zend_Gdata_App_MediaFileSource object
$filesource = $yt->newMediaFileSource('mytestmovie.mov');
$filesource->setContentType('video/quicktime');
// set slug header
$filesource->setSlug('mytestmovie.mov');

// add the filesource to the video entry
$myVideoEntry->setMediaSource($filesource);

$myVideoEntry->setVideoTitle('My Test Movie');
$myVideoEntry->setVideoDescription('My Test Movie');
$myVideoEntry->setVideoCategory('Comedy'); // Note that category must be a valid YouTube category !

// set keywords, please note that this must be a comma separated string
// and that each keyword cannot contain whitespace
$myVideoEntry->setVideoTags('cars, funny');

// upload URI for the currently authenticated user
$uploadUrl = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads';

// try to upload the video, catching a Zend_Gdata_App_HttpException if available
// or just a regular Zend_Gdata_App_Exception
try {
  $newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
} catch (Zend_Gdata_App_HttpException $httpException) {
  echo $httpException->getRawResponseBody();
} catch (Zend_Gdata_App_Exception $e) {
    echo $e->getMessage();
}

我认为它是$newEntry 的一个属性,但我似乎找不到它!

谢谢!

【问题讨论】:

    标签: php zend-framework upload youtube zend-gdata


    【解决方案1】:

    正如您在 the page 上看到的,您从下方获取此代码,$newEntry->getVideoId() 将包含 ID。然后您可以检查其状态(已上传、已处理):

    // Assuming that $newEntry is the object that was returned during the upload
    $state = $newEntry->getVideoState();
    
    if ($state) {
      echo 'Upload status for video ID ' . $newEntry->getVideoId() . ' is ' .
        $state->getName() . ' - ' . $state->getText() . "\n";
      } else {
        echo "Not able to retrieve the video status information yet. " . 
          "Please try again later.\n";
    }
    

    【讨论】:

    • 称我为笨蛋,但我无法将这段代码集成到页面中。你具体是怎么实现的?
    • @Tom - 您需要先实现上传代码,并确保将 $newEntry 替换为您存储上传返回的对象的位置。有关上传代码本身的更多信息,请参阅我帖子中的链接。
    • 我的问题与存储有关。我已经为新 URL 设置了刷新到我的页面,所以它返回 example.com?status=200&id=JPF-DXF7hzc - 我如何“保存”这个值?
    • @Tom - 我不确定你在问什么。如果您的意思是如何存储 ID,PHP 中有很多方法,但这些方法超出了本问题的范围。
    • 这个答案很有用,但我还需要实施此处显示的解决方法以消除错误:groups.google.com/forum/?fromgroups=#!topic/youtube-api-gdata/…
    猜你喜欢
    • 2014-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-14
    • 1970-01-01
    • 1970-01-01
    • 2011-07-31
    • 2015-11-09
    相关资源
    最近更新 更多