-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.php
40 lines (33 loc) · 1.12 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
/**
* @file
*
* Reads data from a Google Spreadsheet that needs authentication.
*/
require 'vendor/autoload.php';
/**
* Set here the full path to the private key .json file obtained when you
* created the service account. Notice that this path must be readable by
* this script.
*/
$service_account_file = '';
/**
* This is the long string that identifies the spreadsheet. Pick it up from
* the spreadsheet's URL and paste it below.
*/
$spreadsheet_id = '';
/**
* This is the range that you want to extract out of the spreadsheet. It uses
* A1 notation. For example, if you want a whole sheet of the spreadsheet, then
* set here the sheet name.
*
* @see https://developers.google.com/sheets/api/guides/concepts#a1_notation
*/
$spreadsheet_range = '';
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $service_account_file);
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(Google_Service_Sheets::SPREADSHEETS_READONLY);
$service = new Google_Service_Sheets($client);
$result = $service->spreadsheets_values->get($spreadsheet_id, $spreadsheet_range);
var_dump($result->getValues());