java - Android application trying to implement login via Google plus shows strange system error -
i trying login via google plus in application, getting strange error , have searched everywhere , regarding same, no luck. below code implementation been done. logcat showing system error of java.lang.illegalargumentexception: googleapiclient parameter required
mainactivity.java
public class mainactivity extends activity implements com.google.android.gms.common.googleplayservicesclient.connectioncallbacks, com.google.android.gms.common.googleplayservicesclient.onconnectionfailedlistener, onclicklistener, onaccessrevokedlistener{ private static final string tag = "mainactivity"; // magic number use know our sign-in error // resolution activity has completed. private static final int our_request_code = 49404; // core google+ client. private plusclient mplusclient; // flag stop multiple dialogues appearing user. private boolean mresolveonfail; // can store connection result failed connect() // attempt in order make application feel bit more // responsive user. private connectionresult mconnectionresult; // progress dialog display when user connecting in // case there delay in of dialogs being ready. private progressdialog mconnectionprogressdialog; private googleapiclient mgoogleapiclient; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); mplusclient = new plusclient.builder(this, this, this) .setactions("http://schemas.google.com/addactivity", "http://schemas.google.com/buyactivity") .build(); // use mresolveonfail flag whether should trigger // resolution of connectionfailed connectionresult. mresolveonfail = false; // connect our sign in, sign out , disconnect buttons. findviewbyid(r.id.sign_in_button).setonclicklistener(this); findviewbyid(r.id.sign_out_button).setonclicklistener(this); findviewbyid(r.id.revoke_access_button).setonclicklistener(this); findviewbyid(r.id.sign_out_button).setvisibility(view.invisible); findviewbyid(r.id.revoke_access_button).setvisibility(view.invisible); // configure progressdialog shown if there // delay in presenting user next sign in step. mconnectionprogressdialog = new progressdialog(this); mconnectionprogressdialog.setmessage("signing in..."); } @override protected void onstart() { super.onstart(); log.v(tag, "start"); // every time start want try connect. if // succeeds we'll onconnected() callback. if // fails we'll onconnectionfailed(), result! mplusclient.connect(); } @override protected void onstop() { super.onstop(); log.v(tag, "stop"); // can little costly keep connection open // google play services, each time our activity // stopped should disconnect. mplusclient.disconnect(); } @override public void onconnectionfailed(connectionresult result) { log.v(tag, "connectionfailed"); // of time, connection fail // user resolvable result. can store in our // mconnectionresult property ready used // when user clicks sign-in button. if (result.hasresolution()) { mconnectionresult = result; if (mresolveonfail) { // local helper function starts // resolution of problem, may // showing user account chooser or similar. startresolution(); } } } @override public void onconnected(bundle bundle) { // yay! can oauth 2.0 access token using. log.v(tag, "connected. yay!"); // turn off flag, if user signs out they'll have // tap sign in again. mresolveonfail = false; // hide progress dialog if showing. mconnectionprogressdialog.dismiss(); // hide sign in button, show sign out buttons. findviewbyid(r.id.sign_in_button).setvisibility(view.invisible); findviewbyid(r.id.sign_out_button).setvisibility(view.visible); findviewbyid(r.id.revoke_access_button).setvisibility(view.visible); // retrieve oauth 2.0 access token. final context context = this.getapplicationcontext(); getprofileinformation(); asynctask task = new asynctask() { @override protected object doinbackground(object... params) { string scope = "oauth2:" + scopes.plus_login; try { // can retrieve token check via // tokeninfo or pass service-side // application. string token = googleauthutil.gettoken(context, mplusclient.getaccountname(), scope); } catch (userrecoverableauthexception e) { // error recoverable, fix // displaying intent user. e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } catch (googleauthexception e) { e.printstacktrace(); } return null; } }; task.execute((void) null); } private void getprofileinformation() { try { if (plus.peopleapi.getcurrentperson(mgoogleapiclient) != null) { person currentperson = plus.peopleapi .getcurrentperson(mgoogleapiclient); string personname = currentperson.getdisplayname(); string personphotourl = currentperson.getimage().geturl(); string persongoogleplusprofile = currentperson.geturl(); string email = plus.accountapi.getaccountname(mgoogleapiclient); log.e(tag, "name: " + personname + ", plusprofile: " + persongoogleplusprofile + ", email: " + email + ", image: " + personphotourl); txtname.settext(personname); txtemail.settext(email); // default profile url gives 50x50 px image // can replace value whatever dimension want // replacing sz=x personphotourl = personphotourl.substring(0, personphotourl.length() - 2) + profile_pic_size; new loadprofileimage(imgprofilepic).execute(personphotourl); } else { toast.maketext(getapplicationcontext(), "person information null", toast.length_long).show(); } } catch (exception e) { e.printstacktrace(); } } @override public void ondisconnected() { // bye! log.v(tag, "disconnected. bye!"); } protected void onactivityresult(int requestcode, int responsecode, intent intent) { log.v(tag, "activityresult: " + requestcode); if (requestcode == our_request_code && responsecode == result_ok) { // if have successful result, want able // resolve further errors, turn on resolution our // flag. mresolveonfail = true; mplusclient.connect(); } else if (requestcode == our_request_code && responsecode != result_ok) { mconnectionprogressdialog.dismiss(); } } @override public void onclick(view view) { switch (view.getid()) { case r.id.sign_in_button: log.v(tag, "tapped sign in"); if (!mplusclient.isconnected()) { // show dialog signing in. mconnectionprogressdialog.show(); // make sure start resolution (e.g. fire // intent , pop dialog user) errors // come in. mresolveonfail = true; // should have connection result ready resolve, // can start process. if (mconnectionresult != null) { startresolution(); } else { // if don't have 1 though, can start connect in // order retrieve one. mplusclient.connect(); } } break; case r.id.sign_out_button: log.v(tag, "tapped sign out"); // want sign out if we're connected. if (mplusclient.isconnected()) { mplusclient.cleardefaultaccount(); mplusclient.disconnect(); mplusclient.connect(); // hide sign out buttons, show sign in button. findviewbyid(r.id.sign_in_button).setvisibility(view.visible); findviewbyid(r.id.sign_out_button) .setvisibility(view.invisible); findviewbyid(r.id.revoke_access_button).setvisibility( view.invisible); } break; case r.id.revoke_access_button: log.v(tag, "tapped disconnect"); if (mplusclient.isconnected()) { // clear default account in sign out. mplusclient.cleardefaultaccount(); mplusclient.revokeaccessanddisconnect(this); } break; default: // unknown id. } } @override public void onaccessrevoked(connectionresult status) { mplusclient.connect(); // hide sign out buttons, show sign in button. findviewbyid(r.id.sign_in_button).setvisibility(view.visible); findviewbyid(r.id.sign_out_button).setvisibility(view.invisible); findviewbyid(r.id.revoke_access_button).setvisibility(view.invisible); } /** * helper method flip mresolveonfail flag , start resolution * of connenctionresult failed connect() call. */ private void startresolution() { try { mresolveonfail = false; mconnectionresult.startresolutionforresult(this, our_request_code); } catch (sendintentexception e) { // problems, try connect() again new // connectionresult. mplusclient.connect(); } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { int id = item.getitemid(); if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } /** * placeholder fragment containing simple view. */ public static class placeholderfragment extends fragment { public placeholderfragment() { } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_main, container, false); return rootview; } } }
logcat:
java.lang.illegalargumentexception: googleapiclient parameter required. @ com.google.android.gms.internal.eg.b(unknown source) @ com.google.android.gms.plus.plus.a(unknown source) @ com.google.android.gms.internal.ia.getcurrentperson(unknown source) @ com.example.googleplus.mainactivity.getprofileinformation(mainactivity.java:182) @ com.example.googleplus.mainactivity.onconnected(mainactivity.java:153) @ com.google.android.gms.internal.dw$c.onconnected(unknown source) @ com.google.android.gms.internal.dx.b(unknown source) @ com.google.android.gms.internal.dx.bt(unknown source) @ com.google.android.gms.internal.dw$h.b(unknown source) @ com.google.android.gms.internal.dw$h.b(unknown source) @ com.google.android.gms.internal.dw$b.br(unknown source) @ com.google.android.gms.internal.dw$a.handlemessage(unknown source) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:123) @ android.app.activitythread.main(activitythread.java:3729) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:507) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:874) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:632) @ dalvik.system.nativestart.main(native method)
you never set mgoogleapiclient anything.
this replaces old plusclient/gamesclient/appstateclient/etc. clients. create 1 googleapiclient , pass api methods.
where have mplusclient = ...
want replace with
mgoogleapiclient = new googleapiclient.builder() .addapi(plus.api, new plus.plusoptions.builder() .addactivitytypes( "http://schemas.google.com/addactivity", "http://schemas.google.com/buyactivity") .build()) .addconnectioncallbacks(this) .addonconnectionfailedlistener(this) .build()
then delete mplusclient
, use mgoogleapiclient
instead.
Comments
Post a Comment