-
Notifications
You must be signed in to change notification settings - Fork 0
Installation
Renan Diaz edited this page Aug 22, 2025
·
1 revision
This guide will walk you through installing and setting up the Google Sheets Helper library in your PHP project.
Before installing the library, ensure you have:
- PHP 7.4 or higher installed
- Composer package manager installed
- Google Cloud Platform account with Sheets API enabled
- Git (optional, for development)
composer require reandimo/google-sheets-helperAdd to your composer.json:
{
"require": {
"reandimo/google-sheets-helper": "^1.2.0"
}
}Then run:
composer installFor development or testing:
git clone https://github.com/reandimo/google-sheets-helper.git
cd google-sheets-helper
composer install- Go to Google Cloud Console
- Click "Select a project" → "New Project"
- Enter a project name and click "Create"
- In your project, go to "APIs & Services" → "Library"
- Search for "Google Sheets API"
- Click on it and press "Enable"
- Go to "APIs & Services" → "Credentials"
- Click "Create Credentials" → "Service Account"
- Fill in the service account details
- Click "Create and Continue"
- Skip role assignment (click "Continue")
- Click "Done"
- Click on the created service account
- Go to "Keys" tab
- Click "Add Key" → "Create New Key"
- Choose "JSON" format
- Download the file and rename it to
credentials.json
- Go to "APIs & Services" → "Credentials"
- Click "Create Credentials" → "OAuth 2.0 Client IDs"
- Choose "Desktop application" or "Web application"
- Fill in the required information
- Download the file and rename it to
credentials.json
After installation, your project structure should look like:
your-project/
├── composer.json
├── composer.lock
├── vendor/
│ └── reandimo/
│ └── google-sheets-helper/
│ ├── src/
│ ├── firstauth
│ └── README.md
├── credentials.json
├── token.json (will be generated)
└── your-script.php
The library includes a firstauth script for first-time authentication:
php ./vendor/reandimo/google-sheets-helper/firstauthFollow the interactive prompts:
- Open the provided URL in your browser
- Sign in with your Google account
- Grant permissions to the application
- Copy the authorization code from the browser
- Paste the code in the terminal
- Verify the token file was created
If you prefer to handle authentication manually:
<?php
require __DIR__ . '/vendor/autoload.php';
use reandimo\GoogleSheetsApi\Helper;
$sheets = new Helper('path/to/credentials.json', 'path/to/token.json');
$sheets->firstAuth('path/to/token.json');Create a test script to verify everything is working:
<?php
require __DIR__ . '/vendor/autoload.php';
use reandimo\GoogleSheetsApi\Helper;
try {
// Set environment variables
putenv('credentialFilePath=' . __DIR__ . '/credentials.json');
putenv('tokenPath=' . __DIR__ . '/token.json');
// Create instance
$sheets = new Helper();
echo "✅ Google Sheets Helper installed successfully!\n";
echo "✅ Authentication working!\n";
} catch (Exception $e) {
echo "❌ Installation failed: " . $e->getMessage() . "\n";
}Run the test:
php test-installation.phpIf using a service account, you need to share your Google Sheets with the service account email:
-
Find the service account email in your
credentials.jsonfile - Open your Google Sheet
- Click "Share" button
- Add the service account email with "Editor" permissions
- Remove the "Notify people" checkmark
- Click "Share"
# Clear composer cache
composer clear-cache
# Update composer
composer self-update
# Install with verbose output
composer install -v# Make firstauth executable
chmod +x ./vendor/reandimo/google-sheets-helper/firstauth
# Check file permissions
ls -la credentials.json
ls -la token.json- Ensure Google Sheets API is enabled
- Check that credentials file is valid JSON
- Verify service account has proper permissions
- Check API quotas and limits
# Check PHP version
php -v
# Check Composer
composer --version
# Verify library installation
composer show reandimo/google-sheets-helper
# Check file existence
ls -la credentials.json token.jsonAfter successful installation:
- Quick Start Guide - Learn basic usage
- Configuration - Understand library configuration
- Examples - See practical examples
- API Reference - Complete method documentation
If you encounter issues during installation:
- Check the Troubleshooting page
- Review Common Issues
- Open an issue on GitHub
Ready to get started? Move on to the Quick Start Guide to begin using the library!