2

私のウェブサイトでは、ユーザーが私の YouTube アカウントに動画をアップロードできます。アプリケーションを Google (youtube) に接続するために、コンポーネント ClientLogin を次のように使用しました。

//my credentials
$user = 'mymail@gmail.com';
$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 を使用していますか?

4

1 に答える 1

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

このサポートがすぐに提供されることを願っています (少なくとも ClientLogin がなくなる前に!)

于 2012-11-29T07:18:48.563 に答える