android - login Google account in webview using account manager token -


i got access token account manager access google java client api, need open webview having google has logged in through access token got account manager. have idea of this.

i tried using cookies (through this), couldn't achieve it. if know way, please share code snippet.

i found way through cookies use of ubertoken. function should call in separate thread

 public void setcookiestowebview(accountmanager am,account account,context context){     string sid = "";     string lsid = "";     thread ubertokenthread = new thread(new runnable() {             @override             public void run() {                 try {                     sid = am.getauthtoken(account, "sid", null, context, null, null)                             .getresult().getstring(accountmanager.key_authtoken);                 } catch (operationcanceledexception e) {                     e.printstacktrace();                 } catch (authenticatorexception e) {                     e.printstacktrace();                 } catch (ioexception e) {                     e.printstacktrace();                 }                 try {                     lsid = am.getauthtoken(account, "lsid", null, context, null, null)                             .getresult().getstring(accountmanager.key_authtoken);                 } catch (operationcanceledexception e) {                     e.printstacktrace();                 } catch (authenticatorexception e) {                     e.printstacktrace();                 } catch (ioexception e) {                     e.printstacktrace();                 }                   string target_url = "https://www.youtube.com/my_live_events";                 uri issue_auth_token_url =                          uri.parse("https://www.google.com/accounts/issueauthtoken?service=gaia&session=false");                 uri token_auth_url = uri.parse("https://www.google.com/accounts/tokenauth");                  string url = issue_auth_token_url.buildupon().appendqueryparameter("sid", sid)                         .appendqueryparameter("lsid", lsid)                         .build().tostring();                 httppost getubertoken = new httppost(url);                 httpresponse response = null;                 try {                     response = httpclient.execute(getubertoken);                 } catch (clientprotocolexception e1) {                     // todo auto-generated catch block                     e1.printstacktrace();                 } catch (ioexception e1) {                     // todo auto-generated catch block                     e1.printstacktrace();                 }                 httpentity entity = response.getentity();                 string ubertoken = "";                 try {                     ubertoken = entityutils.tostring(entity, "utf-8");                 } catch (parseexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 } catch (ioexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 }                 string getcookiesurl = token_auth_url.buildupon()                         .appendqueryparameter("source", "android-browser")                         .appendqueryparameter("auth", ubertoken)                         .appendqueryparameter("continue", target_url)                         .build().tostring();                 httpget getcookies = new httpget(getcookiesurl);                  httpresponse responsegetcookies = null;                 try {                     responsegetcookies = httpclient.execute(getcookies);                 } catch (clientprotocolexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 } catch (ioexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 }                  mcookiestore = ((abstracthttpclient) httpclient).getcookiestore();                 cookie sessioninfo;                 list<cookie> cookies = mcookiestore.getcookies();                  if (! cookies.isempty()){                     cookiemanager cookiemanager = cookiemanager.getinstance();                     cookiemanager.removesessioncookie();                     cookiesyncmanager.createinstance(getapplicationcontext());                     cookiemanager.setacceptcookie(true);                     for(cookie cookie : cookies){                         sessioninfo = cookie;                         string cookiestring = sessioninfo.getname() + "=" + sessioninfo.getvalue() + "; domain=" + cookie.getdomain();                         cookiemanager.setcookie(sessioninfo.getdomain(), cookiestring);                     }                     cookiesyncmanager.getinstance().sync();                 }                 try {                     thread.sleep(1000);                 } catch (interruptedexception e) {                     e.printstacktrace();                 }              }         });         ubertokenthread.start(); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -