java - Unrecoverable exception while generating token using GoogleAuthUtil -


i want use google authentication login in application .for have followed link followed link

my code :

package com.android.mytokengenerator;  import java.io.ioexception;  import com.google.android.gms.auth.googleauthexception; import com.google.android.gms.auth.googleauthutil; import com.google.android.gms.auth.googleplayservicesavailabilityexception; import com.google.android.gms.auth.userrecoverableauthexception; import com.google.android.gms.common.googleplayservicesutil; import com.google.android.gms.common.scopes;  import android.os.asynctask; import android.os.bundle; import android.accounts.account; import android.accounts.accountmanager; import android.app.activity; import android.app.dialog; import android.content.intent; import android.util.log; import android.view.menu;  public class mainactivity extends activity {     string scope = "audience:server:client_id:server client key";     int my_activitys_auth_request_code = 200;@     override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         new gettoken().execute(null, null, null);      }      @     override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.main, menu);         return true;     }     protected void onactivityresult(int requestcode, int resultcode, intent data) {         if (requestcode == my_activitys_auth_request_code) {             if (resultcode == result_ok) {                 new gettoken().execute(null, null, null);             }         }     }     public class gettoken extends asynctask < void, void, void > {          @         override         protected void doinbackground(void...params) {             // todo auto-generated method stub             getanduseauthtokenblocking();              return null;         }      }     // example of how use googleauthutil in blocking, non-main thread context     void getanduseauthtokenblocking() {          // retrieve token given account , scope. return either         // non-empty string or throw exception.         string[] account = getaccountnames();         (int = 0; < account.length; i++) {             try {                 final string token = googleauthutil.gettoken(mainactivity.this, account[i], "oauth2:" + scopes.plus_profile);                 log.e("token", token);                 // work token.                 //                        if (server indicates token invalid) {                 //                            // invalidate token found bad googleauthutil won't                 //                            // return next time (it may have cached it)                 //                            googleauthutil.invalidatetoken(context, string)(context, token);                 //                            // consider retrying getandusetokenblocking() once more                 //                            return;                 //                        }                 return;             } catch (googleplayservicesavailabilityexception playex) {                 dialog alert = googleplayservicesutil.geterrordialog(                     playex.getconnectionstatuscode(),                     this,                     my_activitys_auth_request_code);              } catch (userrecoverableauthexception userauthex) {                 log.e("userrecoverableauthexception", "userrecoverableauthexception");                 userauthex.printstacktrace();                 // start user recoverable action using intent returned                 // getintent()                 mainactivity.this.startactivityforresult(                     userauthex.getintent(),                     my_activitys_auth_request_code);                 return;             } catch (ioexception transientex) {                 log.e("ioexception", "ioexception");                 transientex.printstacktrace();                  // network or server error, call expected succeed if try again later.                 // don't attempt call again - request                 // fail, you'll hit quotas or back-off.                 return;             } catch (googleauthexception authex) {                 log.e("googleauthexception", "googleauthexception");                 authex.printstacktrace();                  // failure. call not expected ever succeed should not                 // retried.                 return;             } catch (exception e) {                 // todo: handle exception                 e.printstacktrace();             }         }       }     private string[] getaccountnames() {         accountmanager maccountmanager = accountmanager.get(this);         account[] accounts = maccountmanager.getaccountsbytype(             googleauthutil.google_account_type);         string[] names = new string[accounts.length];         (int = 0; < names.length; i++) {             names[i] = accounts[i].name;         }         return names;     } } 

now , when put scope value
string scope = "audience:server:client_id:server client key";
giving exception unknownresource

and when putting value scope string scope = scopes.plus_profile; giving exception

logcat

not getting problem.do need use plusclient connectivity before generating token through googleauthutil.gettoken ().please


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -