ClientLogin을 사용하여이 작업을 수행했습니다. 기본 클래스는 아래와 같습니다. 이 클래스는 인증 요청을 할 준비가 된 Zend HTTP 클라이언트 인스턴스를 반환합니다.
<?php
class GoogleAuthenticator {
public static function authenticate($logger) {
$tokenObj = new Token();
try {
$token = $tokenObj->get($token_name);
if(!empty($token)) {
//load a new HTTP client with our token
$logger->info('Using cached token: ' . $token);
$httpClient = new Zend_Gdata_HttpClient();
$httpClient->setConfig(array(
'maxredirects' => 0,
'strictredirects' => true,
'useragent' => 'uploader/v1' . ' Zend_Framework_Gdata/' . Zend_Version::VERSION
)
);
$httpClient->setClientLoginToken($token);
//attempt to use our token to make an authenticated request. If the token is invalid
// an exception will be raised and we can catch this below
$yt = new Zend_Gdata_YouTube($httpClient, 'uploader/v1', '', $youtube_api_key);
$query = new Zend_Gdata_YouTube_VideoQuery();
$query->setFeedType('top rated');
$query->setMaxResults(1);
$yt->getPlaylistListFeed(null, $query); //ignore the response!
} else {
$logger->info('Generating new HTTP client');
// Need to create a brand new client+authentication
$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
$httpClient =
Zend_Gdata_ClientLogin::getHttpClient(
$username = YOUTUBE_USERNAME_PROD,
$password = YOUTUBE_PASSWORD_PROD,
$service = 'youtube',
$client = null,
$source = 'uploader/v1',
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
// get the token so we can cache it for later
$token = $httpClient->getClientLoginToken();
$tokenObj->destroy($token_name);
$tokenObj->insert($token, $token_name);
}
return $httpClient;
}catch(Zend_Gdata_App_AuthException $e) {
$tokenObj->destroy($token_name);
die("Google Authentication error: " . $e->getMessage());
}catch(Exception $e) {
$tokenObj->destroy($token_name);
die("General error: " . $e->getMessage());
}
} // authenticate()
} // GoogleAuthenticator
?>
당신이 상수가 정의되어 있어야합니다 : 당신이 방법이 필요하므로,
YOUTUBE_USERNAME_PROD
YOUTUBE_PASSWORD_PROD
을 또는 그들을 전달하는 클래스를 수정 토큰이 만료 될 수 있기 때문에 시도/캐치가 필요합니다. 그들을 새로 고칠 수 있습니다. 또한 토큰이 작성된 후에도 유효한지 확인하기 위해 더미 요청을해야합니다.
YouTube는 2 년 전쯤에 10 분이 넘는 동영상을 업로드하지 못하도록 했으므로 유스 케이스가 상당히 어려워졌습니다. 즉, 단일 계정 대신 여러 개의 동영상을 매 10 분마다 업로드하는 것을 허용 할 수 없습니다. 그러나 YouTube는 그 이후로이를 해제했을 수도 있습니다. 행운을 빌어 요.
고맙습니다. 글쎄, 11 월은 멀어졌지만,이 질문이 다시 생길 수 있기 때문에 나는 또 다른 프로젝트를 기다릴 것이다. 나는 대답을 검증 할 수는 없지만 어떻게 든 나 (그리고 다른 사람들)를 도울 것이라고 확신한다. 그것에 대해 구체적인 질문이 있지만 불행히도 다른 시간을 떠나야합니다. 건배, 그리고 다시 한번 많이 고마워. – MEM