I use the new Google Android API for Android , and I can connect and everything that it will allow me to do , but to use SpreadsheetService I need to extract accountName / email from a signed-in user.
How to do it?
Hereβs the code where I am connecting the Google Drive API. It works great.
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(); }
Here, where I use the SpreadsheetService API , but I need an 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 tried this by adding this:
String accountName = Plus.AccountApi.getAccountName(mGoogleApiClient);
... in the onConnected method, but it throws a NullPointerException .
In addition, here are my rights:
<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" />
source share