r/googlecloud • • 3d ago

Google sheets API Key

I really just want an api key to pull info from one of my google sheets. But as i look into this there is this whole rabbit hole of AM admin, and changing the organizations default permissions, and i saw vague mentions of weekly charges. So let me ask this, is there an easier way to get an api key for google sheets, and if not how high is the risk of charges if i set up an organization and do all the steps to get the key though google cloud.

2 Upvotes

14 comments sorted by

3

u/Advanced-Ad4869 3d ago

All you need to do is create a Google cloud project, enable the sheets API on that project then create a service account in that project and add the service account's email address to whatever sheets you want.

2

u/Forward-Vast262 3d ago

Thats the way, service account is dead simple and youre not gonna see any charges unless youre hammering the api 24/7.

2

u/Longjumping-Cold1389 3d ago

by adding the email you mean sharing the sheet with that email? I am super new to all of this sorry if its a stupid question.

2

u/Advanced-Ad4869 3d ago

Yes. Each service account has an email address.

1

u/Longjumping-Cold1389 3d ago

I shared the sheet with the email, and the api is enabled. Do i need to create a key? or is that all i need?

1

u/Advanced-Ad4869 3d ago

You use the identity of the account with the Google SDK of the language you are using. The easiest way is to generate a service account key json that you download. But this is VERY important, that key is a bearer token with no restrictions so you need to safe guard it. You can't share it or commit it to git or like use it client side in a website cuz someone will steal it. You should really read the Google cloud documentation on service accounts before proceeding.

1

u/Longjumping-Cold1389 3d ago

My issue is that i cannot download the key, due to default perms of an organization. I do plan on safe guarding that key, but you mention reading the Google cloud documentation. How important is that, I only really want this 1 key for a project, and didnt read most of it and jumped to reddit. Do you recommend reading all the documentation even if im using it for just 1 thing?

2

u/Advanced-Ad4869 3d ago

Yes you need to understand what you are doing regardless of the scope of your project. If you org admin does not allow service account key creation you should talk with them about other auth strategies for the service account that meet the needs of your app.

1

u/Advanced-Ad4869 3d ago

It's quite common for orgs to disable key gen and download since it's dangerous.

1

u/Longjumping-Cold1389 3d ago

but i made the org

1

u/Advanced-Ad4869 3d ago

It's on by default now in all new orgs.

1

u/Longjumping-Cold1389 3d ago

yk what imma read the documention first ill come back if i have more questions after reading, thank you for your time

1

u/Longjumping-Cold1389 3d ago

when ever i go to download my json key, so i can use my sheet in python, it says my organization, has blocked my ability to do so. am i over complicating this?

1

u/martin_omander Googler 3d ago

The Google Sheets API is free.

Does your code run in Google Cloud, for example on Cloud Run? Then it automatically has a service account and you don't need to download any key.