2014-10-01 68 views
0

我想创建一个使用谷歌oAuth的登录页面。 为此我创建了一个clientID。 在ClientID我已经完成了为Android创建,因为我相信我的应用程序将在Android设备上运行。oAuth使用谷歌API创建混合应用程序

创建客户端ID - >安装的应用程序 - > Android的

我已经做了keytooling与SHA1签署,并创建一个clientId

然后我创建了一个公共API访问。在此我创建了一个Android密钥。我提供了com名称和SHA1细节。由于我使用的是INTEL XDK,因此很容易从那里获取COM命名窗格。

在我的JavaScript代码中,我做了这样的事情来构造URL。

var clientID =“client_id =”; var responeType = “& response_type = code”; var scope =“& scope = profile”; var scope =“& scope = https://www.googleapis.com/auth/calendar.readonly”; var redirectURL =“& redirect_uri = urn:ietf:wg:oauth:2.0:oob”; var url =“https://accounts.google.com/o/oauth2/auth?”+ clientID + responeType + scope + redirectURL +“& approval_prompt = auto”;

然后我已经使用一个XHRRequest得到呼叫此URL

变种XHR =新的XMLHttpRequest(); xhr.open( “GET”,网址,虚假的);
xhr.onload =函数(){ 如果(xhr.readyState == 4 & & xhr.status == 200){
的console.log(this.response); var resp = this.response;

} }  xhr.onerror = function(e) { 
alert("Error : "+e) } xhr.send(); 

我有一个连接到它的事件监听按钮。 我是android新手,特别是oAuth。我让所有类型的错误,例如 如

请复制代码,切换到您的应用,然后粘贴有:

当我按一下按钮我没有看到谷歌的任何登录页面请求允许 但我可以在console.log()中看到数据。

我在这里做什么是错误的。

如果有任何方法使用html5创建混合APP请分享。 也请告诉我,如果我正在写它或wrong.Please指导我。

-S

回答

0

您可以使用此jQuery插件的oauth2:https://github.com/krisrak/jquery-cordova-oauth2

它与Intel XDK

所有你需要做的是与你的OAuth用户端的参数和回调修改下面的电话将有access_token开始拨打电话

$.oauth2({ 
    auth_url: 'https://accounts.google.com/o/oauth2/auth', 
    response_type: 'code', 
    token_url: 'https://accounts.google.com/o/oauth2/token', 
    logout_url: 'https://accounts.google.com/logout', 
    client_id: 'CLIENT-ID-FROM-GOOGLE', 
    client_secret: 'CLIENT-SECRET-FROM-GOOGLE', 
    redirect_uri: 'http://www.yourwebsite.com/oauth2callback', 
    other_params: {scope:'profile'} 
}, function(token, response){ 
    makeAPICalls(token); 
}, function(error, response){ 
    alert(error); 
}); 
相关问题