2017-04-26 67 views
0

我希望能夠檢索使用jQuery科爾多瓦如何使用jquery cordova檢索在Android手機上登錄的Google帳戶?

$登錄Android手機谷歌帳戶(函數(){

 $('#LoginForm').submit(function(){ 

     var loginData = $ ("#LoginForm").serialize(); 
     $.ajax({ 
     type: 'post', 
     url: "http://admin.payerszone.net/api/Login/s_dynamic", 
     data: loginData, 
     crossDomian: true 
    }).done(function (data) { 
     console.log(data); 
     alert(data.cMessage.code) 
     if(data.cMessage.code == "0"){ 

      window.location.href = "Home.html" 
      } 

      else{ 
       window.location.href = "Payment.html" 

      } 
    }).error(function (jqXHR, textStatus, errorThrown) { 
     console.log(jqXHR.responseText || textStatus); 

    }); 


      return false;}); 
    }) 
+0

您之後是指:用戶信息將作爲參數傳遞給回調與其他信息allong傳遞登錄到應用程序?或者您是指在手機中同步的帳戶?如果你的意思是後者,我不認爲你可以,因爲你可以有多個。您需要執行oAuth流程 – jstuartmilne

+0

感謝您的回覆。我如何進行oAuth過程? –

+0

如何在登錄到應用程序後使用jquery cordova檢索在Android手機上登錄的Google帳戶 –

回答

0

您可以使用此科爾多瓦插件要經過登錄過程:

https://github.com/EddyVerbruggen/cordova-plugin-googleplus

window.plugins.googleplus.login(
    { 
     'scopes': '... ', // optional, space-separated list of scopes, If not included or empty, defaults to `profile` and `email`. 
     'webClientId': 'client id of the web app/server side', // optional clientId of your Web application from Credentials settings of your project - On Android, this MUST be included to get an idToken. On iOS, it is not required. 
     'offline': true, // optional, but requires the webClientId - if set to true the plugin will also return a serverAuthCode, which can be used to grant offline access to a non-Google server 
    }, 
    function (obj) { 
     alert(JSON.stringify(obj)); // do something useful instead of alerting 
    }, 
    function (msg) { 
     alert('error: ' + msg); 
    } 
); 

第二個參數是AA回調函數當登錄成功是充分。

obj.email   // '[email protected]' 
obj.userId   // user id 
obj.displayName // 'Eddy Verbruggen' 
obj.familyName  // 'Verbruggen' 
obj.givenName  // 'Eddy' 
obj.imageUrl  // 'http://link-to-my-profilepic.google.com' 
obj.idToken  // idToken that can be exchanged to verify user identity. 
obj.serverAuthCode // Auth code that can be exchanged for an access token and refresh token for offline access 

做好後續的安裝說明,並從谷歌等得到clientsId

希望它可以幫助

+0

感謝您的回答,我會在我的代碼中嘗試 –