user1700184
user1700184

Reputation: 1661

GoogleAuthUtil.getToken() is not returning

In my Android application, I am trying to get Google token to connect to Google Spreadsheets. This is the code that does that:

AsyncTask<String, Void, String> getTokenTask = new AsyncTask<String, Void, String>() {

    @Override
    protected String doInBackground(String... params) {
        Log.i("Groceryviewer", "doInBackground() - Entry");
        String accountName = params[0];
        String token = null;
        try {
            Log.i("Groceryviewer", "Before get token");
            token = GoogleAuthUtil.getToken(LoginHomeActivity.this, accountName, "https://spreadsheets.google.com/feeds https://docs.google.com/feeds");
            Log.i("Groceryviewer", "After get token. Token: " + token);
        } catch (UserRecoverableAuthException e) {
            Log.e("Groceryviewer", "Exception in getToken() - UserRecoverableAuthException", e);
            Log.i("Groceryviewer", "Exception in getToken() - startActivityForResult");
            startActivityForResult(e.getIntent(), USER_ACCEPTS);
        } catch (IOException e) {
            Log.e("Groceryviewer", "Exception in getToken() - IOException", e);
        } catch (GoogleAuthException e) {
            Log.e("Groceryviewer", "Exception in getToken() - GoogleAuthException", e);
        }
        Log.i("Groceryviewer", "doInBackground() - Exit");
        return token;
    }

};
getTokenTask.execute(accountName);

String token = null;
try {
    token = getTokenTask.get();
} catch(ExecutionException e) {
    Log.i("Groceryviewer", "Exception in get() - ExecutionException", e);
} catch (InterruptedException e) {
    Log.i("Groceryviewer", "Exception in get() - InterruptedException", e);
}
Log.i("Groceryviewer", "Token: " + token);

I have added this to AndroidManifest.xml as well:

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

The problem is that getToken does not return at all. Here are my logs:

01-01 17:28:57.583: I/Groceryviewer(1485): doInBackground() - Entry
01-01 17:28:57.583: I/Groceryviewer(1485): Before get token

Can someone help me figure out why this error is happening?

Upvotes: 2

Views: 1720

Answers (1)

eddyparkinson
eddyparkinson

Reputation: 3700

Looks like the scope:

There’s really only one method call you need to use, GoogleAuthUtil.getToken(). It takes three arguments: a Context, an email address, and another string argument called scope.

 private final static String G_SPREADSHEET_SCOPE = 
  "oauth2:https://docs.google.com/feeds/ https://docs.googleusercontent.com/ https://spreadsheets.google.com/feeds/";

http://android-developers.blogspot.com.au/2012/09/google-play-services-and-oauth-identity.html

Upvotes: 1

Related Questions