【问题标题】:Migrate youtube api code version 2 to version 3将 youtube api 代码版本 2 迁移到版本 3
【发布时间】:2017-01-07 18:03:18
【问题描述】:

我在我的 php 代码中使用了 youtube api 版本 2。如何快速将我的代码迁移到版本 3? 我应该获得新的开发者密钥吗?我以前用google developer key:http://code.google.com/apis/youtube/dashboard/,但现在我打不开这个页面,我看到502。这是一个错误。

我的 youtube API 2 代码:

require_once("Zend/Gdata/ClientLogin.php");
require_once("Zend/Gdata/HttpClient.php");
require_once("Zend/Gdata/YouTube.php");
require_once("Zend/Gdata/App/HttpException.php");
require_once('Zend/Uri/Http.php');

$authenticationURL = 'https://www.google.com/youtube/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
    $username = $CFG->videoboard_youtube_email,
    $password = $CFG->videoboard_youtube_password,
    $service = 'youtube',
    $client = null,
    $source = 'VideoBoard',
    $loginToken = null,
    $loginCaptcha = null,
    $authenticationURL);

$yt = new Zend_Gdata_YouTube($httpClient, 'VideoBoard', NULL, $CFG->videoboard_youtube_apikey);

$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();

$accessControlElement = new Zend_Gdata_App_Extension_Element(
    'yt:accessControl', 'yt', 'http://gdata.youtube.com/schemas/2007', ''
);
$accessControlElement->extensionAttributes = array(
    array(
        'namespaceUri' => '',
        'name' => 'action',
        'value' => 'list'
    ),
    array(
        'namespaceUri' => '',
        'name' => 'permission',
        'value' => 'denied'
    ));

$myVideoEntry->extensionElements = array($accessControlElement);

$filesource = $yt->newMediaFileSource($from->fullpatch);
$filesource->setContentType($data->type);
$filesource->setSlug('slug');
$myVideoEntry->setMediaSource($filesource);

$myVideoEntry->setVideoTitle($from->author);
$myVideoEntry->setVideoDescription($from->author);
$myVideoEntry->setVideoCategory('Education');
$myVideoEntry->SetVideoTags('videoboard');

$uploadUrl = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads';

try {
    $newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
} catch (Zend_Gdata_App_HttpException $httpException) {
    echo $httpException->getRawResponseBody();

    $DB->delete_records('videoboard_process', array('id' => $data->id));
} catch (Zend_Gdata_App_Exception $e) {
    echo $e->getMessage();

    $DB->delete_records('videoboard_process', array('id' => $data->id));
}

$itemidyoutube = $newEntry->getVideoId();

if (!empty($itemidyoutube)){
    $DB->set_field($table, "itemyoutube", $itemidyoutube, array("id" => $item->id));
}

【问题讨论】:

    标签: youtube-api


    【解决方案1】:

    您可以参考这个Migration Guide。通常,502 错误可能是由 windows 系统文件损坏引起的。损坏的系统文件条目可能对您的计算机的健康构成真正的威胁。之前也有报道issue 注册时出现临时问题 服务器,建议通过http://code.google.com/apis/youtube/dashboard/gwt/index.html 访问它。这是一个blog 可能的解决方案。

    您也可以查看这些相关的 SO 线程:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多