Php Zend Youtube API-在单个帐户上上载视频?
我想允许任何人在我的网站上注册,在我自己的youtube用户频道上传他们的视频 我不希望他们评论任何视频,或任何需要他们自己登录凭据的内容 我应该使用:ClientLogin授权吗 如果是这样,我如何获得令牌,以便允许我的站点与我的youtube频道帐户进行交互Php Zend Youtube API-在单个帐户上上载视频?,php,youtube-api,zend-gdata,Php,Youtube Api,Zend Gdata,我想允许任何人在我的网站上注册,在我自己的youtube用户频道上传他们的视频 我不希望他们评论任何视频,或任何需要他们自己登录凭据的内容 我应该使用:ClientLogin授权吗 如果是这样,我如何获得令牌,以便允许我的站点与我的youtube频道帐户进行交互 这里的任何灯光都将非常感谢,因为我在这里有点迷路。我已经使用ClientLogin完成了这项工作。下面是一个基本类。此类返回Zend HTTP Client的实例,该实例已准备好发出经过身份验证的请求 <?php class G
这里的任何灯光都将非常感谢,因为我在这里有点迷路。我已经使用ClientLogin完成了这项工作。下面是一个基本类。此类返回Zend HTTP Client的实例,该实例已准备好发出经过身份验证的请求
<?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
?>
或者修改类以传入它们。try/catch是必需的,因为令牌可能会过期,所以您需要找到刷新它们的方法。此外,您还需要发出一个虚拟请求,以确保即使在创建令牌之后该令牌仍然有效
请记住,YouTube(大约2年前)阻止你上传超过10分钟的视频,这使得你的用例非常困难。也就是说,你不能允许代表一个账户上传多个视频,超过每10分钟一次。但YouTube可能从那时起就取消了这一限制。祝你好运因为我在文档中没有找到任何完整的API V3解决方案,所以我一直在互联网上寻找解决方案。最后,我将Python示例移植到PHP,并为其他有相同问题的人写了一篇关于它的博文:
这篇博客文章将Youtube V3 api与OAuth2结合使用,因此您不必担心它被弃用。截至2012年4月20日,V2中的所有其他功能(ClientLogin、AuthSub和OAuth 1.0)均已弃用,谢谢!好吧,现在距离11月还很遥远,但如果这个问题再次出现,我将等待另一个项目——我无法验证答案,但我相信它会以某种方式帮助我(和其他人)。关于这件事,我确实有一些具体的问题,但不幸的是,我必须把它们留到另一个时间。干杯,再次感谢。嵌入的链接不再好了。我从另一个问题的“相关”参考文献中找到了这个问答,仅供参考。@FunkFortyNiner感谢您的评论。我解决了这个链接。
YOUTUBE_USERNAME_PROD
YOUTUBE_PASSWORD_PROD