# README
Here's the English translation of the README.md:
Guide to Getting token.json from Google API
You can follow the steps below or just ask Claude how to do it, I prefer the last one.
1. Create a project on Google Cloud Platform
-
Access Google Cloud Console (https://console.cloud.google.com/)
-
Sign in with your Google account
-
Create a new project:
- Click on the dropdown menu in the top left corner (next to "Google Cloud")
- Click "New Project"
- Enter project name
- Select organization (if applicable)
- Click "Create"
-
Enable Gmail API:
- From the left menu, select "APIs & Services" > "Library"
- Search for "Gmail API"
- Click on Gmail API
- Click "Enable"
-
Configure OAuth consent screen:
- From "APIs & Services" menu, select "OAuth consent screen"
- Choose User Type as "External" (or "Internal" if you use Google Workspace)
- Click "Create"
- Fill in required information:
- App name: Your application name
- User support email: Contact email
- Developer contact information: Contact email
- Click "Save and Continue"
- In the Scopes section, click "Add or Remove Scopes"
- Add necessary scopes (e.g., Gmail API scopes)
- Click "Save and Continue"
- Add test users if needed
- Click "Save and Continue"
2. Get credentials.json
- Access Google Cloud Console
- Create a new project or select an existing one
- In the menu, select "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth client ID"
- Choose Application type as "Desktop app"
- Name your credential and click "Create"
- Download credentials.json and place it in the same directory as main.go
3. Run the program
- Open terminal and cd to the directory containing main.go
- Run the command:
go run main.go -credentials=/path/to/google-credentials.json -token=/path/to/google-token.json
Remember the paths, because you will need them in the next step.
4. Authenticate and get token
- The program will display a URL. Copy this URL
- Open the URL in your browser
- Sign in to your Google account
- Accept the requested access permissions
- Google will provide an authorization code
- Copy this authorization code
- Return to terminal and paste the authorization code
- Press Enter
5. Results
- The program will automatically create
token.json
file in the current directory - This token.json contains access token and refresh token
- You can use this token for subsequent API access
- The program will display the list of labels in your Gmail
6. Configure the MCP
Set the path of two file as following key in your claude config file:
{
...
"GOOGLE_CREDENTIALS_FILE": "/path/to/google-credentials.json",
"GOOGLE_TOKEN_FILE": "/path/to/google-token.json",
...
}
Notes
- token.json contains sensitive information, don't share it
- Tokens have expiration dates but will auto-refresh
- If you change scopes in the code, you need to delete the old token.json and create a new one
Common Error Handling
-
If unable to read credentials.json:
- Check if the file exists in the directory
- Verify the filename is exactly "credentials.json"
-
If authorization code is invalid:
- Ensure you copied the code correctly and completely
- Try generating a new code
-
If access is denied:
- Check scopes in the code
- Confirm Gmail API is enabled in Google Cloud Console