I’m building a simple web form and need to send the submitted data directly to my Google spreadsheet. Right now it seems like I have to use OAuth2 which means users get redirected to Google’s login page every time they submit the form. This is really annoying for my users. Is there any legitimate way to write data to my own Google Sheet without forcing visitors to authenticate? I’m working with PHP on the backend if that matters. Looking for a clean solution that doesn’t involve any workarounds or hacks.
Service accounts are exactly what you need. Had the same headache building a customer feedback form last year. Instead of dealing with OAuth redirects, just create a Google Cloud service account - it’ll generate JSON credentials that authenticate your app directly. You’ll need to enable the Google Sheets API, create the service account, download the credentials file, and share your spreadsheet with the service account email. Your PHP code uses these credentials to authenticate automatically - no user interaction needed. I use the google/apiclient library in PHP and it works great. Users submit forms without ever seeing Google’s auth pages since everything happens server-side with your service account credentials.
webhooks could work if u don’t want to deal with apis. I use zapier for this - just hook ur form to google sheets through their webhook setup. Costs a few bucks monthly but saves tons of dev time & users don’t have to deal with auth. zapier handles all the google stuff.
Google Apps Script is your best bet. I had a similar issue last year with a client’s contact form. To avoid the OAuth hassle on your PHP backend, create a Google Apps Script that acts as a web app endpoint. You can write a simple script in the script editor that handles POST requests and directly writes data into your sheet. It runs under your Google account, which means no user authentication is required. Once deployed as a web app with permissions set to ‘anyone’, you’ll get a URL that can accept form submissions. Just configure your PHP to send a POST request to that URL. The setup is quick and effective, allowing for a smooth user experience without the OAuth complications.