I’m having trouble connecting to Google Drive from my Android app running on an emulator. I’ve set up everything according to the official documentation but keep getting authentication errors.
Here’s what I’ve configured so far:
Permissions in AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
Activity configuration:
<activity
android:name="com.myapp.MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="com.google.android.apps.drive.APP_ID"
android:value="123456789-abcdefghijklmnop.apps.googleusercontent.com" />
</activity>
Java code for API client:
if (driveApiClient == null) {
driveApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.setAccountName("[email protected]")
.build();
}
driveApiClient.connect();
I keep getting INVALID_KEY errors in the logs. I’ve created both OAuth credentials and API keys in the Google Console, but the authentication still fails. Since I’m using an emulator, I’m not sure about the SHA1 fingerprint requirements. What am I missing here?