<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mechastorm / google-spreadsheet-exporter example snippets
use Mechastorm\Google\ApiHelper;
use Mechastorm\Google\Spreadsheet\Data\Exporter;
use Mechastorm\Google\Spreadsheet\Data\FormatWriters\LangPhpWriter;
use Mechastorm\Google\Spreadsheet\Data\Transformers\LocalePhpArray;
// Get the json encoded access token.
$authResponse = ApiHelper::getAuthByServiceAccount(
array(
'application_name' => 'name_of_application',
'client_id' => 'service_account_client_id',
'client_email' => 'service_account_client_email',
'key_file_location' => 'location-to-your-private-key-p12-file', // This is the location of the P12 private key file you had donwloaded
)
);
$accessToken = $authResponse->access_token;
echo 'Service Account Access Token: ' . $accessToken;
// Connect to the Google Spreadsheet
$gSSExporter = new Exporter(array(
'access_token' => $accessToken,
'spreadsheet_name' => 'google-spreadsheet-exporter Sample Spreadsheet' // It must match EXACTLY the name
));
$gSSExporter->setWorksheets();
// Instantiate a transformer
$transformer = new LocalePhpArray(array(
'locales' => array(
'en_GB', // Must match the columns on the spreadsheet
'fr_CA',
'my_MY',
'ja_JP',
),
));
// Instantiate a write
$outputFolder = 'sample_output';
$writer = new LangPhpWriter(array(
'path' => $outputFolder,
));
// Process the worksheets and output them to the desired format
$gSSExporter->processWorksheets(
array(
'Web Copy', // It must match EXACTLY the name
),
$transformer,
$writer
);
echo "Done - please check {$outputFolder} for the files\n";
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.