I've created a spreadsheet, which I managed to successfully update with some data using the google api library and by creating a service accounts credentials from Google console -> Api & Services -> Credentials.
My problem is to try to restrict the access of the spreadsheet file. If don't allow to be publicly available for everyone with Editor roles, it will not work. I m getting this message:
{ "error": { "code": 403, "message": "The caller does not have permission", "errors": [ { "message": "The caller does not have permission", "domain": "global", "reason": "forbidden" } ], "status": "PERMISSION_DENIED" } } If I allow for everyone to access my spreadsheet, like in the image below , it will work . 
I am also running my script, which updates the spreadsheet via a cronjob. Also this is the code where I do the auth part and I'm using the data from my Service Contract:
$client = new Google_Client(); $client->setApplicationName('Google Sheets and PHP'); $configuration = '{ "type": "'.$apiConfig['keyFile']['type'].'", "project_id": "'.$apiConfig['projectId'].'", "private_key_id": "'.$apiConfig['keyFile']['private_key_id'].'", "private_key": "'.$key.'", "client_email": "'.$apiConfig['keyFile']['client_email'].'", "client_id": "'.$apiConfig['keyFile']['client_id'].'", "auth_uri": "'.$apiConfig['keyFile']['auth_uri'].'", "token_uri": "'.$apiConfig['keyFile']['token_uri'].'", "auth_provider_x509_cert_url": "'.$apiConfig['keyFile']['auth_provider_x509_cert_url'].'", "client_x509_cert_url": "'.$apiConfig['keyFile']['client_x509_cert_url'].'" }'; $client->setAuthConfig(json_decode($configuration, true)); $client->setScopes([Google_Service_Sheets::SPREADSHEETS]); $client->setAccessType('offline'); return new Google_Service_Sheets($client); Does anyone have any clue how can I restrict the access? and still have this work?
Thanks a lot for any suggestions
