代码之家  ›  专栏  ›  技术社区  ›  murze

如何获取刚刚上传的YouTube电影的视频ID

  •  3
  • murze  · 技术社区  · 14 年前

    如何获取刚刚上传的YouTube电影的视频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 但我似乎找不到它!

    谢谢!

    1 回复  |  直到 14 年前
        1
  •  4
  •   Arda Xi    14 年前

    如你所见 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";
    }