Search code examples
google-sheetsgoogle-sheets-apigoogle-oauthgspread

Public/Private keys for Google developers service account


I've been going over this for a while and can't manage to understand how to obtain my public/private keys for my automatically created service account in the google developers console.

I am making a python script that imports data using gspread from a google spreadsheet, and to authenticate myself through SignedJwtAssertionCredentials I need an existent service account

The issue is:

I create a new project using: "Create a project"

But then when I go to Permissions/Permissions, I see that the service account I need is already created, but I don't have the keys for it.

I want to know how to get the @developer.gserviceaccount.com keys since I have already tried importing data from google spreadsheets using my other @xxx-22324.iam.gserviceaccount.com with no luck, it says the email address does not exist.

EDIT:

Whenever I go to API Manager / Credentials I only get the possibility to generate a key for my @mxxx-22324.iam.gserviceaccount.com (The one that I can't use)


Solution

  • I solved my issue:

    Google has updated its service account detail format and also it's way of sharing Spreadsheets with service accounts so that they can be accessible from gspread.

    I created then a service account with the new formating : xxx@montredo-22324.iam.gserviceaccount.com and set the exact same file google generates as a JSON to be read by my application:

    login = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope)
    

    then shared without notifications the spreadsheet with my service account email (the same in the JSON file I just mentioned)

    and voila.