我正在构建一个使用Youtube API访问的Chrome扩展程序。但我没有得到对Youtube的认证。它看起来像没有最新的来源或样本。这里的Tutorial使用了一些从2010年开始的chrome-oauth库,其他Source这里使用了不同的lib,我猜它对基于浏览器的Auth & API访问很有用。 我有一个开发密钥,已安装应用程序的客户端ID(类型:Chrome),YT API密钥(简单API访问)。Chrome Ext。使用Youtube API v3的OAuth 2.0
我的Chrome应用使用下面的清单:
{
"name": "Youtube Chrome Ext",
"version": "1.0",
"manifest_version": 2,
"description": "Youtube Chrome Ext",
"app": {
"launch": {
"local_path": "main.html",
"container":"tab"
}
},
"options_page": "settings.html",
"background": {
"page": "background.html"
},
"permissions": [
"tabs",
"http://gdata.youtube.com/",
"https://www.google.com/accounts/OAuthGetRequestToken",
"https://www.google.com/accounts/OAuthAuthorizeToken",
"https://www.google.com/accounts/OAuthGetAccessToken",
"https://www.googleapis.com/auth/youtube"
]
}
与以下backgroundHandler.js在OAuth2.0的文件进行认证与YouTube:
(function(global){
global.backgroundHandler = {
initBackground : function(){
var self = this;
var oauth = ChromeExOAuth.initBackgroundPage({
'request_url' : 'https://www.google.com/accounts/OAuthGetRequestToken',
'authorize_url' : 'https://www.google.com/accounts/OAuthAuthorizeToken',
'access_url' : 'https://www.google.com/accounts/OAuthGetAccessToken',
'consumer_key' : 'anonymous',
'consumer_secret' : 'anonymous',
'scope' : 'http://gdata.youtube.com',
'app_name' : 'YouTube Ext'
});
oauth.authorize(this.onAuthorized());
},
onAuthorized : function() {
//I'm not authorized - no window with grant access was displayed ...
}
};
})(window);
document.addEventListener('DOMContentLoaded', function() {
backgroundHandler.initBackground();
});
注意的Youtube不使用消费者密钥&秘密。
background.html:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="js/oAuth/chrome_ex_oauthsimple.js"></script>
<script type="text/javascript" src="js/oAuth/chrome_ex_oauth.js"></script>
<script type="text/javascript" src="js/handler/backgroundHandler.js"></script>
</head>
<body>
</body>
</html>
我最大的问题是得到某种方式的OAuth的完成,做对的Youtube authentificated请求。看起来对于我来说,整个www是最新的,没有任何信息来源。
如果有人能帮助我,我会很高兴。
BR, mybecks
您是否遇到了任何错误?我仔细观察了代码,发现v2和v3正在进行混合。我建议先得到一个非CWS示例,然后按顺序查找关键字和范围,然后查看CWS。我们有一个JS示例正在等待发布到文档站点,但它不是Chrome应用程序示例。 – 2013-02-14 15:19:25