2017-01-07 103 views
0

我在我的php代碼中使用了youtube api版本2。我如何快速將我的代碼遷移到版本3? 我應該得到新的開發人員密鑰嗎?我之前使用過Google開發者密鑰:http://code.google.com/apis/youtube/dashboard/,但現在無法打開此頁面,我看到了502。這是一個錯誤。將youtube api代碼版本2遷移到版本3

enter image description here

我的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)); 
} 

回答

0

你可以參考這個Migration Guide。通常,502錯誤可能是由windows系統文件損壞引起的。損壞的系統文件條目可能會對您計算機的健康造成真正的威脅。還有一個報告issue之前有一個臨時問題與註冊 服務器,建議訪問它在http://code.google.com/apis/youtube/dashboard/gwt/index.html。這裏有一個blog可能的解決方案。

你也可以檢查與這些相關的SO線程: