You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I run my program I get this error.
Fatal error: Uncaught exception 'Google\Spreadsheet\Exception\UnauthorizedException' with message 'You need permission' in /Users/nickwoelk/Desktop/migration_form_to_sheets/vendor/asimlqt/php-google-spreadsheet-client/src/Google/Spreadsheet/DefaultServiceRequest.php:356
I've already granted permissions to the spreadsheet and am able to read and create a new row. But it won't write my values to the spreadsheet.
`<?php
require DIR . '/vendor/autoload.php';
use Google\Spreadsheet\ServiceRequestFactory;
use Google\Spreadsheet\DefaultServiceRequest;
// creates a new Google Access Token
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . DIR . '/client_secret.json');
$client = new Google_Client;
$client->useApplicationDefaultCredentials();
$client->setApplicationName("Migration form to Sheets");
$client->setScopes(['https://www.googleapis.com/auth/drive','https://spreadsheets.google.com/feeds']);
if ($client->isAccessTokenExpired()) {
$client->refreshTokenWithAssertion();
}
$accessToken = $client->fetchAccessTokenWithAssertion()["access_token"];
$serviceRequest = new DefaultServiceRequest($accessToken);
ServiceRequestFactory::setInstance($serviceRequest);
// Get our spreadsheet
$spreadsheet = (new Google\Spreadsheet\SpreadsheetService)
->getSpreadsheetFeed()
->getByTitle('Churn');
// Get the first worksheet (tab)
$worksheets = $spreadsheet->getWorksheetFeed()->getEntries();
$worksheet = $worksheets[0];
When I run my program I get this error.
Fatal error: Uncaught exception 'Google\Spreadsheet\Exception\UnauthorizedException' with message 'You need permission' in /Users/nickwoelk/Desktop/migration_form_to_sheets/vendor/asimlqt/php-google-spreadsheet-client/src/Google/Spreadsheet/DefaultServiceRequest.php:356
I've already granted permissions to the spreadsheet and am able to read and create a new row. But it won't write my values to the spreadsheet.
`<?php
require DIR . '/vendor/autoload.php';
use Google\Spreadsheet\ServiceRequestFactory;
use Google\Spreadsheet\DefaultServiceRequest;
// creates a new Google Access Token
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . DIR . '/client_secret.json');
$client = new Google_Client;
$client->useApplicationDefaultCredentials();
$client->setApplicationName("Migration form to Sheets");
$client->setScopes(['https://www.googleapis.com/auth/drive','https://spreadsheets.google.com/feeds']);
if ($client->isAccessTokenExpired()) {
$client->refreshTokenWithAssertion();
}
$accessToken = $client->fetchAccessTokenWithAssertion()["access_token"];
$serviceRequest = new DefaultServiceRequest($accessToken);
ServiceRequestFactory::setInstance($serviceRequest);
// Get our spreadsheet
$spreadsheet = (new Google\Spreadsheet\SpreadsheetService)
->getSpreadsheetFeed()
->getByTitle('Churn');
// Get the first worksheet (tab)
$worksheets = $spreadsheet->getWorksheetFeed()->getEntries();
$worksheet = $worksheets[0];
$listFeed = $worksheet->getListFeed();
// Inserts newdata into new row
$listFeed->insert([
'migration_date' => '',
'store_url' => 'mystore.myshopify.com',
'ticket_link' => '',
'subscriber_count' => "200",
'variation_of_active_customers' => '',
'percentage' => '',
'coming_from' => '',
'why_are_they_migrating' => '',
//...
]);
?>`
The text was updated successfully, but these errors were encountered: