{"id":6016,"date":"2014-04-11T23:17:10","date_gmt":"2014-04-11T23:17:10","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/11\/android-application-trying-to-implement-login-via-google-plus-shows-strange-system-error-collection-of-common-programming-errors\/"},"modified":"2014-04-11T23:17:10","modified_gmt":"2014-04-11T23:17:10","slug":"android-application-trying-to-implement-login-via-google-plus-shows-strange-system-error-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/11\/android-application-trying-to-implement-login-via-google-plus-shows-strange-system-error-collection-of-common-programming-errors\/","title":{"rendered":"Android application trying to implement login via Google plus shows strange system error-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/gFj7E.jpg?s=32&amp;g=1\" \/><br \/>\nDeep Rathod<\/p>\n<p>I am trying to login via Google plus in my application, however i am getting very strange error and which i have searched almost everywhere and everything regarding the same, but no luck. Below is my Code where the implementation is been done. The logcat is showing the system error of java.lang.IllegalArgumentException: GoogleApiClient parameter is required<\/p>\n<p>MainActivity.java<\/p>\n<pre><code>public class MainActivity extends Activity implements com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks, com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener, OnClickListener, OnAccessRevokedListener{\n\nprivate static final String TAG = \"MainActivity\";\n\n\/\/ A magic number we will use to know that our sign-in error\n\/\/ resolution activity has completed.\nprivate static final int OUR_REQUEST_CODE = 49404;\n\n\/\/ The core Google+ client.\nprivate PlusClient mPlusClient;\n\n\n\/\/ A flag to stop multiple dialogues appearing for the user.\nprivate boolean mResolveOnFail;\n\n\/\/ We can store the connection result from a failed connect()\n\/\/ attempt in order to make the application feel a bit more\n\/\/ responsive for the user.\nprivate ConnectionResult mConnectionResult;\n\n\/\/ A progress dialog to display when the user is connecting in\n\/\/ case there is a delay in any of the dialogs being ready.\nprivate ProgressDialog mConnectionProgressDialog;\n\nprivate GoogleApiClient mGoogleApiClient;\n\n\n@Override\nprotected void onCreate(Bundle savedInstanceState) {\n    super.onCreate(savedInstanceState); \n    setContentView(R.layout.activity_main);\n\n\n\n    mPlusClient = new PlusClient.Builder(this, this, this)\n            .setActions(\"http:\/\/schemas.google.com\/AddActivity\",\n                    \"http:\/\/schemas.google.com\/BuyActivity\")\n            .build();\n\n            \/\/ We use mResolveOnFail as a flag to say whether we should trigger\n            \/\/ the resolution of a connectionFailed ConnectionResult.\n            mResolveOnFail = false;\n\n            \/\/ Connect our sign in, sign out and disconnect buttons.\n            findViewById(R.id.sign_in_button).setOnClickListener(this);\n            findViewById(R.id.sign_out_button).setOnClickListener(this);\n            findViewById(R.id.revoke_access_button).setOnClickListener(this);\n            findViewById(R.id.sign_out_button).setVisibility(View.INVISIBLE);\n            findViewById(R.id.revoke_access_button).setVisibility(View.INVISIBLE);\n\n            \/\/ Configure the ProgressDialog that will be shown if there is a\n            \/\/ delay in presenting the user with the next sign in step.\n            mConnectionProgressDialog = new ProgressDialog(this);\n            mConnectionProgressDialog.setMessage(\"Signing in...\");\n\n}\n@Override\nprotected void onStart() {\n    super.onStart();\n    Log.v(TAG, \"Start\");\n    \/\/ Every time we start we want to try to connect. If it\n    \/\/ succeeds we'll get an onConnected() callback. If it\n    \/\/ fails we'll get onConnectionFailed(), with a result!\n    mPlusClient.connect();\n}\n\n@Override\nprotected void onStop() {\n    super.onStop();\n    Log.v(TAG, \"Stop\");\n    \/\/ It can be a little costly to keep the connection open\n    \/\/ to Google Play Services, so each time our activity is\n    \/\/ stopped we should disconnect.\n    mPlusClient.disconnect();\n}\n\n@Override\npublic void onConnectionFailed(ConnectionResult result) {\n    Log.v(TAG, \"ConnectionFailed\");\n    \/\/ Most of the time, the connection will fail with a\n    \/\/ user resolvable result. We can store that in our\n    \/\/ mConnectionResult property ready for to be used\n    \/\/ when the user clicks the sign-in button.\n    if (result.hasResolution()) {\n        mConnectionResult = result;\n        if (mResolveOnFail) {\n            \/\/ This is a local helper function that starts\n            \/\/ the resolution of the problem, which may be\n            \/\/ showing the user an account chooser or similar.\n            startResolution();\n        }\n    }\n}\n\n@Override\npublic void onConnected(Bundle bundle) {\n    \/\/ Yay! We can get the oAuth 2.0 access token we are using.\n    Log.v(TAG, \"Connected. Yay!\");\n\n    \/\/ Turn off the flag, so if the user signs out they'll have to\n    \/\/ tap to sign in again.\n    mResolveOnFail = false;\n\n    \/\/ Hide the progress dialog if its showing.\n    mConnectionProgressDialog.dismiss();\n\n    \/\/ Hide the sign in button, show the sign out buttons.\n    findViewById(R.id.sign_in_button).setVisibility(View.INVISIBLE);\n    findViewById(R.id.sign_out_button).setVisibility(View.VISIBLE);\n    findViewById(R.id.revoke_access_button).setVisibility(View.VISIBLE);\n\n    \/\/ Retrieve the oAuth 2.0 access token.\n    final Context context = this.getApplicationContext();\n\n    getProfileInformation();\n\n    AsyncTask task = new AsyncTask() {\n        @Override\n        protected Object doInBackground(Object... params) {\n            String scope = \"oauth2:\" + Scopes.PLUS_LOGIN;\n            try {\n                \/\/ We can retrieve the token to check via\n                \/\/ tokeninfo or to pass to a service-side\n                \/\/ application.\n                String token = GoogleAuthUtil.getToken(context,\n                        mPlusClient.getAccountName(), scope);\n            } catch (UserRecoverableAuthException e) {\n                \/\/ This error is recoverable, so we could fix this\n                \/\/ by displaying the intent to the user.\n                e.printStackTrace();\n            } catch (IOException e) {\n                e.printStackTrace();\n            } catch (GoogleAuthException e) {\n                e.printStackTrace();\n            }\n            return null;\n        }\n    };\n    task.execute((Void) null);\n}\n\nprivate void getProfileInformation() {\n    try {\n        if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {\n            Person currentPerson = Plus.PeopleApi\n                    .getCurrentPerson(mGoogleApiClient);\n            String personName = currentPerson.getDisplayName();\n            String personPhotoUrl = currentPerson.getImage().getUrl();\n            String personGooglePlusProfile = currentPerson.getUrl();\n            String email = Plus.AccountApi.getAccountName(mGoogleApiClient);\n\n            Log.e(TAG, \"Name: \" + personName + \", plusProfile: \"\n                    + personGooglePlusProfile + \", email: \" + email\n                    + \", Image: \" + personPhotoUrl);\n\n            txtName.setText(personName);\n            txtEmail.setText(email);\n\n            \/\/ by default the profile url gives 50x50 px image only\n            \/\/ we can replace the value with whatever dimension we want by\n            \/\/ replacing sz=X\n            personPhotoUrl = personPhotoUrl.substring(0,\n                    personPhotoUrl.length() - 2)\n                    + PROFILE_PIC_SIZE;\n\n            new LoadProfileImage(imgProfilePic).execute(personPhotoUrl);\n\n        } else {\n            Toast.makeText(getApplicationContext(),\n                    \"Person information is null\", Toast.LENGTH_LONG).show();\n        }\n    } catch (Exception e) {\n        e.printStackTrace();\n    }\n}\n@Override\npublic void onDisconnected() {\n    \/\/ Bye!\n    Log.v(TAG, \"Disconnected. Bye!\");\n}\n\nprotected void onActivityResult(int requestCode, int responseCode,\n        Intent intent) {\n    Log.v(TAG, \"ActivityResult: \" + requestCode);\n    if (requestCode == OUR_REQUEST_CODE &amp;&amp; responseCode == RESULT_OK) {\n        \/\/ If we have a successful result, we will want to be able to\n        \/\/ resolve any further errors, so turn on resolution with our\n        \/\/ flag.\n        mResolveOnFail = true;\n\n        mPlusClient.connect();\n    } else if (requestCode == OUR_REQUEST_CODE &amp;&amp; responseCode != RESULT_OK) {\n\n        mConnectionProgressDialog.dismiss();\n    }\n}\n\n@Override\npublic void onClick(View view) {\n    switch (view.getId()) {\n    case R.id.sign_in_button:\n        Log.v(TAG, \"Tapped sign in\");\n        if (!mPlusClient.isConnected()) {\n            \/\/ Show the dialog as we are now signing in.\n            mConnectionProgressDialog.show();\n            \/\/ Make sure that we will start the resolution (e.g. fire the\n            \/\/ intent and pop up a dialog for the user) for any errors\n            \/\/ that come in.\n            mResolveOnFail = true;\n            \/\/ We should always have a connection result ready to resolve,\n            \/\/ so we can start that process.\n            if (mConnectionResult != null) {\n                startResolution();\n            } else {\n                \/\/ If we don't have one though, we can start connect in\n                \/\/ order to retrieve one.\n                mPlusClient.connect();\n            }\n        }\n        break;\n    case R.id.sign_out_button:\n        Log.v(TAG, \"Tapped sign out\");\n        \/\/ We only want to sign out if we're connected.\n        if (mPlusClient.isConnected()) {\n\n            mPlusClient.clearDefaultAccount();\n\n\n            mPlusClient.disconnect();\n            mPlusClient.connect();\n\n            \/\/ Hide the sign out buttons, show the sign in button.\n            findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);\n            findViewById(R.id.sign_out_button)\n                    .setVisibility(View.INVISIBLE);\n            findViewById(R.id.revoke_access_button).setVisibility(\n                    View.INVISIBLE);\n        }\n        break;\n    case R.id.revoke_access_button:\n        Log.v(TAG, \"Tapped disconnect\");\n        if (mPlusClient.isConnected()) {\n            \/\/ Clear the default account as in the Sign Out.\n            mPlusClient.clearDefaultAccount();\n\n            mPlusClient.revokeAccessAndDisconnect(this);\n        }\n        break;\n    default:\n        \/\/ Unknown id.\n    }\n}\n\n@Override\npublic void onAccessRevoked(ConnectionResult status) {\n\n    mPlusClient.connect();\n\n    \/\/ Hide the sign out buttons, show the sign in button.\n    findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);\n    findViewById(R.id.sign_out_button).setVisibility(View.INVISIBLE);\n    findViewById(R.id.revoke_access_button).setVisibility(View.INVISIBLE);\n}\n\n\/**\n * A helper method to flip the mResolveOnFail flag and start the resolution\n * of the ConnenctionResult from the failed connect() call.\n *\/\nprivate void startResolution() {\n    try {\n\n        mResolveOnFail = false;\n\n        mConnectionResult.startResolutionForResult(this, OUR_REQUEST_CODE);\n    } catch (SendIntentException e) {\n        \/\/ Any problems, just try to connect() again so we get a new\n        \/\/ ConnectionResult.\n        mPlusClient.connect();\n    }\n}\n\n@Override\npublic boolean onCreateOptionsMenu(Menu menu) {\n\n    \/\/ Inflate the menu; this adds items to the action bar if it is present.\n    getMenuInflater().inflate(R.menu.main, menu);\n    return true;\n}\n\n@Override\npublic boolean onOptionsItemSelected(MenuItem item) {\n\n    int id = item.getItemId();\n    if (id == R.id.action_settings) {\n        return true;\n    }\n    return super.onOptionsItemSelected(item);\n}\n\n\/**\n * A placeholder fragment containing a simple view.\n *\/\npublic static class PlaceholderFragment extends Fragment {\n\n    public PlaceholderFragment() {\n    }\n\n    @Override\n    public View onCreateView(LayoutInflater inflater, ViewGroup container,\n            Bundle savedInstanceState) {\n        View rootView = inflater.inflate(R.layout.fragment_main, container,\n                false);\n        return rootView;\n    }\n}\n\n}\n<\/code><\/pre>\n<p>Logcat:<\/p>\n<pre><code>java.lang.IllegalArgumentException: GoogleApiClient parameter is required.\nat com.google.android.gms.internal.eg.b(Unknown Source)\nat com.google.android.gms.plus.Plus.a(Unknown Source)\nat com.google.android.gms.internal.ia.getCurrentPerson(Unknown Source)\nat com.example.googleplus.MainActivity.getProfileInformation(MainActivity.java:182)\nat com.example.googleplus.MainActivity.onConnected(MainActivity.java:153)\nat com.google.android.gms.internal.dw$c.onConnected(Unknown Source)\nat com.google.android.gms.internal.dx.b(Unknown Source)\nat com.google.android.gms.internal.dx.bT(Unknown Source)\nat com.google.android.gms.internal.dw$h.b(Unknown Source)\nat com.google.android.gms.internal.dw$h.b(Unknown Source)\nat com.google.android.gms.internal.dw$b.bR(Unknown Source)\nat com.google.android.gms.internal.dw$a.handleMessage(Unknown Source)\nat android.os.Handler.dispatchMessage(Handler.java:99)\nat android.os.Looper.loop(Looper.java:123)\nat android.app.ActivityThread.main(ActivityThread.java:3729)\nat java.lang.reflect.Method.invokeNative(Native Method)\nat java.lang.reflect.Method.invoke(Method.java:507)\nat com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)\nat com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)\nat dalvik.system.NativeStart.main(Native Method)\n<\/code><\/pre>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/d771736cfe1b549ecaf0ac00a787d8b7?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nHounshell<\/p>\n<p>You never set mGoogleApiClient to anything.<\/p>\n<p>This replaces the old PlusClient\/GamesClient\/AppStateClient\/etc. clients. You create one GoogleApiClient and pass it into any API methods.<\/p>\n<p>Where you have <code>mPlusClient = ...<\/code> you want to replace that with<\/p>\n<pre><code>mGoogleApiClient = new GoogleApiClient.Builder()\n    .addApi(Plus.API, new Plus.PlusOptions.Builder()\n        .addActivityTypes(\n            \"http:\/\/schemas.google.com\/AddActivity\",\n            \"http:\/\/schemas.google.com\/BuyActivity\")\n        .build())\n    .addConnectionCallbacks(this)\n    .addOnConnectionFailedListener(this)\n    .build()\n<\/code><\/pre>\n<p>Then delete <code>mPlusClient<\/code> and use <code>mGoogleApiClient<\/code> instead.<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Deep Rathod I am trying to login via Google plus in my application, however i am getting very strange error and which i have searched almost everywhere and everything regarding the same, but no luck. Below is my Code where the implementation is been done. The logcat is showing the system error of java.lang.IllegalArgumentException: GoogleApiClient [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6016","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6016","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6016"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6016\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6016"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6016"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6016"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}