【问题标题】:Get the Video URL after uploading a video to Youtube using Data API - php使用 Data API 将视频上传到 Youtube 后获取视频 URL - php
【发布时间】:2011-08-19 05:43:42
【问题描述】:

我正在尝试使用 PHP 数据 API 将视频上传到 YouTube

$yt = new Zend_Gdata_YouTube($httpClient);
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();

$filesource = $yt->newMediaFileSource('mytestmovie.mov');
$filesource->setContentType('video/quicktime');
$filesource->setSlug('mytestmovie.mov');

$myVideoEntry->setMediaSource($filesource);

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

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

// Optionally set some developer tags
$myVideoEntry->setVideoDeveloperTags(array('mydevelopertag',
                                           'anotherdevelopertag'));

// Optionally set the video's location
$yt->registerPackage('Zend_Gdata_Geo');
$yt->registerPackage('Zend_Gdata_Geo_Extension');
$where = $yt->newGeoRssWhere();
$position = $yt->newGmlPos('37.0 -122.0');
$where->point = $yt->newGmlPoint($position);
$myVideoEntry->setWhere($where);

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

// Try to upload the video, catching a Zend_Gdata_App_HttpException
// if availableor 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 对象中获取上传视频的 URL。

任何帮助将不胜感激:)

【问题讨论】:

标签: php youtube-api


【解决方案1】:

试试这个:

try {
            $newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl,
    'Zend_Gdata_YouTube_VideoEntry');
            $id = $newEntry->getVideoId(); // YOUR ANSWER IS HERE :)
            echo $id; 
    }

【讨论】:

猜你喜欢
  • 2014-04-10
  • 2012-12-23
  • 2015-04-21
  • 2011-10-12
  • 2015-11-19
  • 1970-01-01
  • 2014-08-03
  • 2014-11-26
  • 2014-06-05
相关资源
最近更新 更多