-2

I have followed this tutorial in order to get the access token and it works as shown in the link. Now how do I get the email and profile pic from this? I have implemented found this tutorial which shows me how to quick start with google+ signin.

But in this how do I get the access token?

I have found these links which shows me the basic part but can anyone say me where do I need to implement them ?

So how do I use this using AsyncTask

Finally I would like to get the access token, email and profile pic and how from anyone of the tutorial?

Any suggestions are welcome.

Community
  • 1
  • 1
coder
  • 13,002
  • 31
  • 112
  • 214

1 Answers1

1

Few ways. This is the easiest to understand. First, build a class extending AsyncTask<>. You want a String[] to be the return type. Note: AsyncTask<Params, Progress, Result> so if you want to return a string, you need to extend AsyncTask<Void, Void, String>

 public class YourAsyncTaskName extends AsyncTask<Void, Void, String> {
        @Override
        protected String doInBackground(Void... params) {
            String token = null;

            try {
                token = GoogleAuthUtil.getToken(
                        MainActivity.this,
                        mGoogleApiClient.getAccountName(),
                        "oauth2:" + SCOPES);
            } catch (IOException transientEx) {
                // Network or server error, try later
                Log.e(TAG, transientEx.toString());

            } catch (UserRecoverableAuthException e) {
                // Recover (with e.getIntent())
                Log.e(TAG, e.toString());  

            } catch (GoogleAuthException authEx) {
                // The call is not ever expected to succeed
                // assuming you have already verified that 
                // Google Play services is installed.
                Log.e(TAG, authEx.toString());
            }

            return token;
        }

        @Override
        protected void onPostExecute(String token) {
            /* here you have your token */
            Log.i(TAG, "Access token retrieved:" + token);
        }

 } 

Then to start this task, just create an instance and call .execute();

YourAsyncTaskName asyncTask = new AsyncTaskName();
asyncTask.execute();
Chad Bingham
  • 32,650
  • 19
  • 86
  • 115