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