Modifying a public Google Sheet via API without OAuth in Android

I’m stuck trying to update a public Google Sheet using the API in my Android app. The sheet is set to ‘anyone can edit’ but I keep getting a 401 error saying I don’t have valid credentials.

It’s weird because I can read data from the sheet just fine. I had to use a browser API key for that though since the Android key didn’t work.

Is there a way to update the sheet without OAuth? Here’s what I’ve tried so far:

Sheets sheetsService = new Sheets.Builder(transport, jsonFactory, null)
    .setApplicationName('MyApp')
    .build();

String spreadsheetId = 'abc123';
String range = 'Sheet1!A1:B2';
ValueRange body = new ValueRange()
    .setValues(Arrays.asList(
        Arrays.asList('New', 'Data')
    ));

sheetsService.spreadsheets().values()
    .update(spreadsheetId, range, body)
    .setKey('my-browser-api-key')
    .execute();

Any ideas on how to make this work? Or is updating not possible without full auth?

hey, i’ve run into this too. it’s a pain, but you gotta use oauth for writing to sheets, even public ones. google’s pretty strict bout that. maybe try setting up a simple backend api that handles the oauth stuff and updating? then your app just talks to that instead. keeps things simpler on the android side atleast

I’ve encountered similar issues when working with Google Sheets API. Unfortunately, updating sheets without OAuth is not possible, even for public sheets. Google’s security model requires authenticated requests for write operations to prevent abuse.

Your best bet is to implement OAuth 2.0 in your Android app. It’s more complex but necessary for updating sheets. You’ll need to set up OAuth credentials in the Google Cloud Console and use the GoogleSignInClient for authentication.

Alternatively, you could create a server-side component (e.g., a simple web service) that handles the OAuth flow and sheet updates. Your Android app would then make requests to this service instead of directly to the Sheets API. This approach keeps OAuth complexities out of your mobile app but requires additional infrastructure.

As someone who’s worked extensively with the Google Sheets API in Android, I understand the frustration. Updating a sheet without OAuth is tricky. While you can use an API key for reading public data, writing operations almost always require authentication. One possible workaround is to set up a Google Apps Script web app that acts as a middleware. In this setup you create a bound Apps Script that performs the update function and deploy it to allow public access under your authority. Your Android app would then make POST requests to this web app URL. This method bypasses the need for OAuth while still ensuring that updates are securely handled by adding a simple API key or secret in your requests.