home / infca / gss (navigation links)

.

P1 | P2 Links | End | mapa

GSS

go 2 top fons groc

Homepage, documentation,

nou GSS
Create a new GSS

Fem :

  1. entra a Google Sheets (login required, as bcn.sag@g.c + bxxsxx2kXV) i crea un full de càlcul nou
  2. posa-li un bon nom descriptiu, com "Dades Corolla"
  3. mira la URL del navegador, entre "/d/" i "/edit" - aquest és l'ID del full de càlcul (spreadsheet_id)
    https://docs.google.com/spreadsheets/d/1gQoOKyXngYTLe_2vd9IL5QrLqnaEdnvtAgPzyyl9sBU/edit?gid=0#gid=0 ID = 1gQoOKyXngYTLe_2vd9IL5QrLqnaEdnvtAgPzyyl9sBU
  4. despeses Corolla
Configurar Google Cloud i el Compte de Servei

Perquè python es pugui autenticar sense que hagi d'obrir cap finestra del navegador, cal crear credencials de Service Account

  1. Ves a Google Cloud Console i crea un projecte : "despesa del Corolla"
  2. Activa les API necessàries:
    1. Ves a APIs & Services > Library (API i serveis > Biblioteca).
    2. Busca "Google Sheets API" i fes clic a Enable (Activa).
    3. Torna a la biblioteca, busca "Google Drive API" i activa-la també
  3. Crea un Compte de servei (Service Account):
    1. Ves a APIs & Services > Credentials (API i serveis > Credencials). {Remember to configure the OAuth consent screen with information about your application.}
    2. Fes clic a "+ Create Credentials" and select "Service account" from drop-down
    3. Assigna-li un nom (per exemple, python-sheets-writer) i fes clic a Create and continue.
    4. En el pas del rol, pots deixar-lo en blanc o assignar-li un rol bàsic si cal, i fes clic a Done.
  4. Descarrega la clau JSON:
    1. A la llista de comptes de servei, fes clic sobre el compte que acabes de crear "despesa del Corolla"
      Pots buscar "Service Accounts" i seleccionar el teu : "python-sheets-writer@despesa-del-corolla.iam.gserviceaccount.com"
    2. Ves a la pestanya Keys (Claus).
    3. Fes clic a "Add key" -> "Create new key", tria el format JSON i descarrega el fitxer "despesa-del-corolla-3b54d0bd8903.json"
    4. Important: Guarda aquest fitxer (p. ex. credencials.json) en un lloc segur i no el pugis mai a repositoris públics com GitHub.
  5. Compartir el full de càlcul amb el Compte de Servei:

    Aquest és el pas que sovint es passa per alt i provoca errors de permisos:

    1. Obre el fitxer credencials.json i busca el camp "client_email". Tindrà un aspecte semblant a:python-sheets-writer@el-teu-projecte.iam.gserviceaccount.com
    2. Copia aquesta adreça de correu : "client_email": "python-sheets-writer@despesa-del-corolla.iam.gserviceaccount.com",
    3. Torna al teu Google Sheets, fes clic al botó Share (Comparteix, a dalt a la dreta), enganxa l'adreça del Service Account i assigna-li el rol d'Editor.
    4. Desa els canvis (no cal enviar notificació).
  6. Connectar i escriure dades des de Python
    1. Instal·la gspread i google-auth al teu entorn de Python: "pip install gspread google-auth"
    2. run "/home/sebas/dades/ai/irina_corolla/1_write_test.py"
  7. Fer accessible el full per determinades persones
    1. en el GSS, piquem "Share" dalt a la dreta
    2. posem els emails i la seva funcio ("editor" or "reader")

Autoritzacio

Si quan anem a escriure en una GSS des python i ens surt ...

# Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A60191%2F&state=pA4cZSbGPoJlEJOtNkmrDypAi2VWOC&access_type=offline

Explicacio de Google :

el projecte "un mes de EFV a GSS" has not completed the Google verification process. The app is currently being tested and can only be accessed by developer-approved testers. If you think that you should have access, contact the developer. If you are a developer of un mes de EFV a GSS, see error details. Error 403: access_denied

Solucio de Gemini :

That error happens because your Google Cloud project's OAuth consent screen is currently set to Testing mode, and the Google account you are trying to sign in with isn't listed as an approved tester.

Since this is a personal or internal script, you do not need to go through Google's formal app verification process. You just need to whitelist your email address in the Google Cloud Console:

  1. go to the Google Cloud Console and make sure your project ("xatGPT", no "un mes de EFV a GSS") is selected in the top dropdown bar.
  2. in the left navigation menu, go to "APIs & Services" -> "OAuth consent" screen
  3. scroll down to the "Test users" section (or look under the Audience tab, depending on your console view)
  4. click "+ Add users"
  5. enter the exact Gmail or Google Workspace email address you are using to authenticate in your browser, and click Save.

Once saved, run your script again. You will still see a warning screen saying "Google hasn't verified this app", which is completely normal for apps in Testing mode — just click Continue (or Advanced - Go to un mes de EFV a GSS (unsafe)) to grant access.

Alternative (Recommended for automated scripts):

If you are the only one using this script and don't want to deal with browser logins or expiring OAuth tokens, switch to a Service Account instead.

You create a service account in Google Cloud, download its JSON key, and simply share your Google Sheet with the service account's @...iam.gserviceaccount.com email address just like you would with a colleague.

Ineligible accounts not added
The following email addresses are either not associated with a Google Account or the account is not eligible for designation as a test user: i----i.m-------s@gmail.com

That error occurs because the Google Cloud OAuth consent screen User Type is set to Internal rather than External. When set to Internal, Google only allows email addresses belonging to your specific Google Workspace organization domain (for example, @yourdomain.com) and automatically blocks standard @gmail.com accounts from being added as test users.

Solucio :

To allow your @gmail.com address, switch the audience type to External:


Links


Ep ! Valid HTML 4.01!   Valid CSS! Escriu-me !
Updated 20261116 (a)  
Uf !