Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

You need permission Error #185

Open
nickwoelk opened this issue Dec 9, 2017 · 0 comments
Open

You need permission Error #185

nickwoelk opened this issue Dec 9, 2017 · 0 comments

Comments

@nickwoelk
Copy link

nickwoelk commented Dec 9, 2017

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' => '',
//...
]);

?>`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant