Follow these steps to create a service account and obtain its JSON credentials file for accessing Google Sheets through the gspread
library.
- Visit the Google Cloud Console.
- Create a new project or select an existing one.
- Navigate to the "APIs & Services > Dashboard" section.
- Click on "+ ENABLE APIS AND SERVICES".
- Search for "Google Sheets API" and enable it.
- Go to "IAM & Admin > Service Accounts".
- Click on "Create Service Account".
- Enter a service account name and description.
- Click "Create".
- Assign roles if specific permissions are required (optional).
- Optionally, grant users access to this service account.
- In the service accounts list, find your new account.
- Go to the "Keys" tab.
- Click on "Add Key" and select "Create new key".
- Choose "JSON" as the key type and download the JSON file.
- Rename the downloaded JSON file to
service_account.json
. - Place it in the same directory as your script or update the script's path to the JSON file.
- Open your Google Sheet.
- Share it with the email address of the service account (found in the JSON file).
Ensure you handle the JSON file securely as it provides access to your Google Cloud resources.