2012-07-12 20 views
2

我的網站允許用戶上傳視頻到我的youtube帳戶。要連接我aplication谷歌(YouTube)的我使用的成分ClientLogin的是這樣的:谷歌OAuth和Zend連接使用我的應用程序的憑據

//my credentials 
$user = '[email protected]'; 
$pass = 'mypass'; 
$service = 'youtube'; 
$developerKey = 'mydevkey'; 

//create the http client 
$httpClient = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service, null, 
       Zend_Gdata_ClientLogin::DEFAULT_SOURCE,null,null, 
       Zend_Gdata_ClientLogin::CLIENTLOGIN_URI,'GOOGLE'); 
$httpClient->setHeaders('X-GData-Key', 'key='. $developerKey); 

//create the instances 
$youTubeService = new Zend_Gdata_YouTube($httpClient); 
$newVideoEntry = new Zend_Gdata_YouTube_VideoEntry(); 
$newVideoEntry->setVideoTitle("test video"); 
$newVideoEntry->setVideoDescription("just testing"); 
$newVideoEntry->setVideoCategory("Music"); 
$newVideoEntry->setVideoTags('test, api'); 

//call the API to get the upload url and token 
$tokenHandlerUrl = 'https://gdata.youtube.com/action/GetUploadToken'; 
try { 
    $tokenArray = $youTubeService->getFormUploadToken($newVideoEntry, $tokenHandlerUrl); 
} catch (Exception $e) { 

} 
$tokenValue = $tokenArray['token']; 
$postUrl = $tokenArray['url']; 

但現在的ClientLogin被棄用:S,我需要使用OAuth 2 ...但已經閱讀文檔,它關於使用我的應用憑證(而不是用戶的憑證)進行連接沒有任何說明。有沒有辦法重現這個代碼,但使用oAuth?

+0

我也試圖找到一個解決方案(至少是ClientLogin的消失之前!)爲了這。你是如何設法完成的? – s3v3n 2012-11-07 01:56:16

+0

現在我必須這樣做。我已經讀到ClientLogin仍然會[2015年之前可用](https://developers.google.com/accounts/terms),所以現在我猜,沒關係,直到我找到更好的解決方案 – pleasedontbelong 2012-11-07 09:31:35

+0

是的,我猜信息是正確的:https://developers.google.com/accounts/terms。非常感謝你! – s3v3n 2012-11-07 16:14:57

回答

1

從理論上講,用的OAuth2做到這一點的方法是使用一個服務帳戶:

https://developers.google.com/accounts/docs/OAuth2ServiceAccount

一旦賬戶是建立在你的API控制檯,它就會允許服務器到服務器交互。不幸的是,Youtube的API尚不支持服務帳戶:

https://code.google.com/p/google-api-php-client/wiki/OAuth2#Service_Accounts

希望這支持將很快到來

+0

謝謝:)我也希望它。 – pleasedontbelong 2012-11-29 11:05:43

相關問題