Google sheets integration with php

  google-sheets, php

We’re updating an existing form so we can also add data to a Google sheet. I’m trying to follow the tutorial at
Srijan.net.

We’ve got the spreadsheet built, Composer is handling the dependencies, we’ve got the project created and enabled, got the credentials.json file created and loaded and a test page running.

However, when we run the page, it simply says ‘The page isn’t working’. I’ve got error messaging turned on, but it is not showing anything. All we are trying to do at this point is just connect to the sheet we have.

As near as I can tell, the url for the sheet is: https://docs.google.com/spreadsheets/d/1_kWSdoKHGJerrk-WkTYySuEvrcj1Kks9pO-MtqFJl-U/edit#gid=0. That makes the SheetID ‘1_kWSdoKHGJerrk-WkTYySuEvrcj1Kks9pO-MtqFJl-U’for the sheet ID.

The sum total of the code to this point is:
require __DIR__ . '/vendor/autoload.php';

//Reading data from spreadsheet.

$client = new Google_Client();

$client->setApplicationName('Google Sheets and PHP');

$client->setScopes([Google_Service_Sheets::SPREADSHEETS]);

$client->setAccessType('offline');

$client->setAuthConfig(__DIR__ . '/credentials.json');

$service = new Google_Service_Sheets($client);
$spreadsheetId = "1_kWSdoKHGJerrk-WkTYySuEvrcj1Kks9pO-MtqFJl-U"; //It is present in your URL
//
$get_range = "A1:B10”;

It’s blowing up on the $get_range statement and, even though errors are turned on. they aren’t yielding anything

We’ve never done anything like this before so don’t know why there is an error or what to do about it. Any assistance would be greatly appreciated and thank you invance.

Source: Ask PHP

LEAVE A COMMENT