To use this library, you need a Google Service Account, which allows your application to authenticate and access your Google Sheet on your behalf. Follow these steps to get the necessary credentials.
- Go to the Google Cloud Console.
- If you don't have a project, create one by clicking the project dropdown at the top of the page and selecting "New Project".
- Give your project a name and click "Create".
- In your project's dashboard, navigate to the "APIs & Services" > "Library" section.
- Search for "Google Sheets API".
- Click on it and then click the "Enable" button.
- In the "APIs & Services" section, go to "Credentials".
- Click "Create Credentials" and select "Service account".
- Fill in the service account details:
- Service account name: Give it a descriptive name (e.g., "Spreadsheet ORM Bot").
- Service account ID: This will be generated automatically.
- Description: Optional, but helpful.
- Click "Create and Continue".
- Grant access (Optional): You can skip granting this service account a role for now by clicking "Continue".
- Grant users access (Optional): You can also skip this step. Click "Done".
-
You should now see your newly created service account in the credentials list.
-
Click on the service account's email address to manage it.
-
Go to the "KEYS" tab.
-
Click "Add Key" and select "Create new key".
-
Choose JSON as the key type and click "Create".
-
A JSON file will be automatically downloaded to your computer. This is your credential file. Keep it safe and do not commit it to public repositories!
The downloaded JSON file will contain your
client_emailandprivate_key.
- Open the Google Sheet you want to use as a database.
- Click the "Share" button in the top-right corner.
- In the downloaded JSON file, find the
client_emailvalue (it looks like...-..@...iam.gserviceaccount.com). - Paste this email address into the "Add people and groups" field.
- Give it "Editor" permissions.
- Click "Send" (or "Share").
You are now ready to use the credentials in your application!