I'm using the new Google Drive Android API and I can connect, and do all that it will allow me to do, but in order to use the SpreadsheetService, I need to extract the accountName/email from the signed in user.
How do I do that?
Here's the code where I connect the Google Drive API. It works fine.
private void connect() {
if (isGooglePlayServicesAvailable()) {
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
// And, connect!
if (!mGoogleApiClient.isConnecting() && !mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
writeLog("Connecting...");
}
}
}
Here's where I'm using the SpreadsheetService API, but I need the account name to get the token.
String accountName = "???"; // how do I get this From GoogleClientApi / mGoogleApiClient ?
String accessToken = GoogleAuthUtil.getTokenWithNotification(GDriveActivity.this, accountName, scope, null);
SpreadsheetService service = new SpreadsheetService("v1");
I have tried this adding this:
String accountName = Plus.AccountApi.getAccountName(mGoogleApiClient);
... in the onConnected
method, but it throws a NullPointerException
.
Also, here are my permissions:
<uses-permission
android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission
android:name="android.permission.VIBRATE" />
<uses-permission
android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.GET_ACCOUNTS" />
<uses-permission
android:name="android.permission.NETWORK" />
<uses-permission
android:name="android.permission.USE_CREDENTIALS" />