This method allows you to import data from private Google Sheets. However, be aware that the credentials used for access will be visible to anyone who can view your Count canvas. Use this method with caution if security is a primary concern.
Steps:
Create a Service Account:
Go to the GCP APIs dashboard.
Select Library and search for and enable both Google Drive API and Google Sheets API.
Go back to the APIs dashboard and select Credentials > Create credentials > Service account.
Create a new service account and download the JSON key file.
Share the Sheet with Your Service Account:
Open your Google Sheet and click the Share button.
Under "People with access," invite the email address of your service account. You can find this email in the JSON key file you downloaded.
Access the Sheet Data in Count:
In your Count canvas, create a new Python cell.
Paste the following code, replacing the placeholder values in the
credentials
dictionary with the information from your downloaded JSON key file. Also, replace'YOUR_SHEET_NAME'
and'YOUR_WORKSHEET_NAME'
with the correct names.
Python
import gspread
import pandas as pd
credentials = {
'type': 'service_account',
'project_id': 'YOUR_PROJECT_ID',
'private_key_id': 'YOUR_PRIVATE_KEY_ID',
'private_key': 'YOUR_PRIVATE_KEY',
'client_email': 'YOUR_CLIENT_EMAIL',
'client_id': 'YOUR_CLIENT_ID',
'auth_uri': 'https://accounts.google.com/o/oauth2/auth',
'token_uri': 'https://oauth2.googleapis.com/token',
'auth_provider_x509_cert_url': 'https://www.googleapis.com/oauth2/v1/certs',
'client_x509_cert_url': 'https://www.googleapis.com/robot/v1/metadata/x509/YOUR_CLIENT_EMAIL',
'universe_domain': 'googleapis.com'
}
gs = gspread.service_account_from_dict(credentials)
sheet = gs.open('YOUR_SHEET_NAME')
worksheet = sheet.worksheet('YOUR_WORKSHEET_NAME')
pd.DataFrame.from_records(worksheet.get_all_records())Run the cell to import your data into a Count dataframe.