- Get a service account key from https://console.cloud.google.com/apis/credentials (You can here also restrict what this keys is allowed todo)
- When creating, make sure you click the
Furnish a new private key
- Select
JSON
when it asks you how to download the key.
- When creating, make sure you click the
- The
service account key
you have just generated includes aclient_email
.- Go to you google spreadsheet and allow this
client_email
to have write access on this document
- Go to you google spreadsheet and allow this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$sheet_name = "Sheet1"; $google_client = new \Google_Client(); $google_client->setApplicationName('Google Sheets Updater'); $google_client->setScopes([\Google_Service_Sheets::SPREADSHEETS]); $google_client->setAuthConfig(storage_path('jsondownload.json')); $service = new \Google_Service_Sheets($google_client); $spreadsheet_id = 'your_sheet_id'; $range = $sheet_name.'!A:C'; $params = [ 'valueInputOption' => "USER_ENTERED" ]; $value_array = ["1","2","3","4","5","6"]; $body = new \Google_Service_Sheets_ValueRange([ 'values' => [$value_array] ]); $service->spreadsheets_values->append($spreadsheet_id, $range, $body, $params); |
https://stackoverflow.com/questions/44045183/access-google-spreadsheet-api-without-auth-token