使用Youtube API,我試圖編寫一個腳本,列出用戶擁有的所有未加標籤的視頻,無論是公共,私人還是不公開。首先,我使用用戶的憑據進行身份驗證:Youtube API v2 - 查詢之間的身份驗證有所不同?
require_once 'Zend/Loader.php'; // the Zend dir must be in your include_path
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
try {
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = $Youtube_Login["Username"],
$password = $Youtube_Login["Password"],
$service = 'youtube',
$client = null,
$source = 'NAME', // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);
} catch (Exception $e) {
$err[] = $e->getMessage();
return false;
}
然後,我嘗試以兩種方式返回列表。我第一次嘗試使用查詢從數據庫中提取只是uncaptioned視頻:
try{
$query = $yt->newVideoQuery();
$query->setParam('caption', 'false');
$query->setParam('author', $Youtube_Login["Username"]);
$query->orderBy = 'viewCount';
$videoFeed = $yt->getVideoFeed($query);
} catch (Zend_Gdata_App_Exception $e) {
$err[] = $e->getMessage();
end_script(false);
}
然而,私營和非公開影片是從結果中丟失。因此,對於第二次嘗試,我用的是getUserUploads()函數來把所有的視頻,然後檢查他們的失蹤字幕:
try{
$videoFeed = $yt->getuserUploads($Youtube_Login["Username"]);
} catch (Zend_Gdata_App_Exception $e) {
$err[] = $e->getMessage();
end_script(false);
}
foreach ($videoFeed as $videoEntry) {
foreach ($videoEntry->link as $link) {
if($link->rel == "http://gdata.youtube.com/schemas/2007#video.captionTracks"){
if($link->extensionAttributes['http://gdata.youtube.com/schemas/2007:hasEntries']['value'] == 'false'){
// Video has no caption entries, print entry info
}
}
}
}
這將返回我正確的結果,但在效率的成本,速度,和數據傳輸。由於Google每天只允許進行大量數據傳輸,並且由於視頻數量很大(並且在不斷增加),因此這是一個次優解決方案。
有沒有什麼辦法可以正確驗證第一次嘗試,以便找到我的客戶還需要列出的未發佈和未列出的視頻?或者,另一種完全不涉及下載和遍歷整個視頻列表的方式?
謝謝!
更新:
我已經與我的僱主討論這一點,OAuth是不是一種選擇,2個或3條腿。
那麼,有沒有完全沒有辦法驗證newVideoQuery()函數?即使是視頻擁有者,是否有意阻止無法檢索視頻的個人數據?
有沒有辦法做到這一點,而不強迫來自用戶的手動登錄,只是用他們的憑據?這是一個應該在命令行,遠程服務器上運行的腳本,我不希望重定向。 – Ripptor 2013-05-09 21:12:07
研究網絡應用程序的三腳OAuth。 – AronVietti 2013-05-09 21:43:11
其實,我不相信這能解決問題。我目前正在進行身份驗證,因爲我可以在第二次嘗試中訪問私人列表。問題是從第一次嘗試獲得經過驗證的用戶結果。 除非OAuth進程以不同的方式使用getVideoFeed()函數嗎? – Ripptor 2013-05-09 22:01:38