Access Not Configured Error with Drive API Integration

I’m encountering a 403 Forbidden error when trying to connect to the Drive API in my Android application. The error message indicates “Access Not Configured” despite having enabled both the Drive SDK and Drive API in my console setup.

Here’s a sample of my code that manages authentication and file retrieval:

package com.driveapp.cloudexample;

import java.io.IOException;
import java.util.List;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.google.android.gms.auth.GoogleAuthUtil;
import com.google.android.gms.auth.UserRecoverableAuthException;
import com.google.android.gms.common.AccountPicker;
import com.google.api.client.auth.oauth2.BearerToken;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.android2.AndroidHttp;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.DriveScopes;
import com.google.api.services.drive.model.File;
import com.google.api.services.drive.model.FileList;

public class CloudActivity extends Activity {
    private static final int SELECT_ACCOUNT = 1;
    private String userToken;
    private Button connectButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_layout);
        
        connectButton = (Button) findViewById(R.id.connect_btn);
        connectButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                selectUserAccount();
            }
        });
    }

    private void selectUserAccount() {
        Intent picker = AccountPicker.newChooseAccountIntent(
            null, null, new String[]{"com.google"}, false, null, null, null, null);
        startActivityForResult(picker, SELECT_ACCOUNT);
    }

    private void authenticateUser(Account userAccount) {
        AsyncTask<Account, Void, String> authTask = new AsyncTask<Account, Void, String>() {
            @Override
            protected String doInBackground(Account... accounts) {
                try {
                    return GoogleAuthUtil.getToken(
                        CloudActivity.this, 
                        accounts[0].name, 
                        "oauth2:" + DriveScopes.DRIVE);
                } catch (Exception e) {
                    e.printStackTrace();
                    return null;
                }
            }

            @Override
            protected void onPostExecute(String token) {
                if (token != null) {
                    userToken = token;
                    fetchCloudFiles();
                }
            }
        };
        authTask.execute(userAccount);
    }

    private Drive createDriveService() {
        HttpTransport transport = AndroidHttp.newCompatibleTransport();
        JacksonFactory jsonFactory = new JacksonFactory();
        Credential creds = new Credential(BearerToken.authorizationHeaderAccessMethod())
            .setAccessToken(userToken);
        
        return new Drive.Builder(transport, jsonFactory, creds).build();
    }

    private void fetchCloudFiles() {
        Drive driveService = createDriveService();
        try {
            Drive.Files.List fileQuery = driveService.files().list();
            FileList results = fileQuery.execute(); // This line throws the exception
            
            List<File> items = results.getItems();
            Log.d("CloudApp", "Found files: " + items.size());
            
            for (File item : items) {
                Log.d("CloudApp", "File: " + item.getTitle());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == SELECT_ACCOUNT && resultCode == RESULT_OK) {
            String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            // Handle account selection
        }
    }
}

The problem occurs at the execute() function where I receive a 403 error related to “usageLimits” with the reason “accessNotConfigured.” Although I’ve enabled the relevant APIs and tried several client IDs, I’m still unsure what I may have missed in setting everything up.

Had this exact issue last year. The problem was my package name in the code didn’t match what I’d registered in Google Console. Double-check that “com.driveapp.cloudexample” matches exactly what’s in your OAuth 2.0 client credentials - even tiny typos will cause the 403 error. Also caught me off guard: I was using an old Google Play Services library version. Updating to the latest fixed my auth issues. Try invalidating your token with GoogleAuthUtil.invalidateToken() before requesting a new one too - cached tokens sometimes carry over config problems from old setups.

Check your Google Console project - I’ve seen this when the client ID in your app doesn’t match where the Drive API is enabled. Also make sure billing is set up on that project. APIs sometimes get restricted without billing even when they show as ‘enabled’.

The “accessNotConfigured” error is often tied to issues with your API key rather than your OAuth credentials. It indicates that your API client isn’t connected to the correct Google Cloud project where the Drive API is enabled. I faced a similar situation six months ago and it took me quite a while to resolve. Ensure you’re using the client ID associated with the project where you activated the Drive API. Additionally, verify that you’ve created the OAuth 2.0 client ID specifically for Android applications, making sure the package name and SHA-1 fingerprint are accurate. It’s also crucial to check if you are using the debug or release keystore, as the SHA-1 must match exactly. If problems persist, consider clearing the token cache and re-authenticating after adjusting your setup.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.