Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Sheets use API key instead of client_secret.json

In the QuickStart.java example on Java Quickstart they use OAuth client ID to identify the application, and this pops up a windows asking for Google credentials to use the application. You have to download a client_secret.json to modify a Google Sheet.

My question is: Can you evade the popping up window asking for Google credentials using an API Key or something else? And, if it's possible, how do you change the Java code in order to do that?

like image 424
Mr. Kevin Avatar asked Jan 02 '23 14:01

Mr. Kevin


1 Answers

An API key could only work when accessing the resources owned by the project that created the key.

For resources like spreadsheets, you're typically accessing resources owned by a user. It would be pretty awful if you got access to my private sheets simply by having an API key.

So no, I wouldn't expect there to be any way to avoid getting authorization to work with a user's documents. However, you should be able to use the Java OAuth library to retain the auth token so you can avoid needing to ask for it more than once. (Unless the user revokes access, of course.)

As DalmTo says, you can use service account credentials if you're trying to access resources owned by the project (or which the project can be granted access to). Note that if you're running on AppEngine, Google Kubernetes Engine or Google Compute Engine, the service account credentials for that environment should be available automatically.

like image 176
Jon Skeet Avatar answered Jan 05 '23 16:01

Jon Skeet