This document provides information about the Google Sheets integration feature that allows users to update cells in Google Sheets from the application.
- OAuth authentication with Google
- Individual authentication tokens for each user
- Update cells in Google Sheets
- Simple UI for managing the integration
- Go to the Google Cloud Console
- Create a new project
- Enable the Google Sheets API
- Configure the OAuth consent screen
- Create OAuth 2.0 credentials (Client ID and Client Secret)
Add the following environment variables to your .env file:
GOOGLE_CLIENT_ID=your_client_id
GOOGLE_CLIENT_SECRET=your_client_secret
GOOGLE_REDIRECT_URI=https://your-app.com/app/google-sheets/callback
GOOGLE_PROJECT_ID=your_project_id
Run the database migrations to create the necessary tables:
php artisan migrate- Navigate to
/app/google-sheetsin the application - Click "Connect to Google Sheets" to authorize the application
- Enter the ID of your Google Sheet (found in the URL)
- Use the form to update cells in your spreadsheet
The integration uses a google_auth_tokens table to store OAuth tokens for each user:
user_id: Foreign key to the users tableaccess_token: The OAuth access tokenrefresh_token: The OAuth refresh tokentoken_type: The token type (default: Bearer)expires_at: When the token expiresspreadsheet_id: The ID of the Google Spreadsheet
-
GoogleSheetsService: Handles authentication and API interactions
-
Controllers:
IndexGoogleSheetsWebController: Displays the main pageAuthorizeGoogleSheetsWebController: Handles OAuth redirectCallbackGoogleSheetsWebController: Handles OAuth callbackStoreSpreadsheetIdWebController: Stores the spreadsheet IDUpdateCellWebController: Updates cells in the spreadsheet
-
Views:
index.blade.php: Main interface for the integration
To test the integration:
- Configure the Google Cloud project and environment variables
- Navigate to
/app/google-sheets - Connect your account to Google Sheets
- Enter a valid spreadsheet ID
- Try updating cells in the spreadsheet
- Authentication Errors: Check that your Google Cloud project is properly configured and the redirect URI matches exactly.
- Access Errors: Ensure the Google account has access to the spreadsheet.
- Token Refresh Issues: If tokens aren't refreshing properly, try reconnecting to Google Sheets.
- Add support for reading data from Google Sheets
- Implement batch updates for multiple cells
- Add support for formatting cells
- Create a more advanced spreadsheet editor interface