Get the client_secrets.json file if you don’t have it already. Use the fab newproject command to kick off a new project by copying a basic project structure and setting up a Google spreadsheet.
Tarbell uses the Google Drive API to create new spreadsheets, which requires going through a little OAuth2 song-and-dance. This is optional but highly recommended, in part because Tarbell will probably use this technique for all authentication and access in the future. If you want to skip this step and configure your spreadsheet manually, see Manually creating Google spreadsheets.
You ready? Let’s go.
In order to allow Tarbell to create new Google Spreadsheets, you’ll need to download a client_secrets.json file to access the Google Drive API. You can share this file with collaborators and within your organization, but do not share this file anywhere public.
Log in to the Google API Developer Console and create a new project:
Now click the “Services” tab and enable Google Drive API.
Click the “API Access” tab to create a client ID:
Add some project details. These don’t really matter:
This is the important screen. Select “installed app” and “other”:
Whew! Now you can download the client_secrets.json file:
Now put the file in the root directory of your Tarbell installation.
The first time you run fab newproject and answer yes to create a Google spreadsheet, your default browser will open and you will be prompted to grant your Tarbell client access to your API key.
The fab newproject command will prompt you if the client_secrets.json file doesn’t exist.
The first time you create a new project and spreadsheet, make sure you are not running any services on port 8080, such as MAMP. The Python Google API client library fires up a tiny little server on port 8080 to receive and store an access token during this cycle. Because the access token is stored, you won’t need to do again unless your token is revoked. You can restore any port 8080 services indefinitely.
Help us improve! We know this step is a little rocky. We’d like to make it smoother. If you are an OAuth or Google Drive API expert, we need your help. See #21 Improve OAuth workflow for newproject command and #22 Use Drive API in Tarbell library.
To create your first project, use the handy fab command:
You’ll be prompted with a series of questions. Here’s what you’ll see the first time you it with user input highlighted.
To manually set up a Google spreadsheet for your project:
Create a new Google spreadsheet
Rename “Sheet1” to “values”
Add ‘key’ and ‘value’ column headers in the first row
Add the spreadsheet key in projectname/config.py
- Public access:
- Set the spreadsheet to ‘publish to the web’
- Private access:
- Grant access to a special user account (you’ll be storing password in the clear, so set up a new account for this)
- Add credentials to projectname/secrets.py