我正在構建一個使用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