I have read a lot of articles :
Google Calendar API – PHP https://developers.google.com/calendar/quickstart/php
and others.. I want to use the service account, I gave permissions for my calendar, I have downloaded the json key. If I use the code from Google, I got:
missing the required redirect URI
If i use the code:
$client = new GoogleClient();
$client->setApplicationName('Gcal');
$client->setAuthConfig($key_file_location);
$client->setScopes([Google_Service_Calendar::CALENDAR]);
$client->setSubject($calendarId);
$client->setAccessType('offline');
$service = new Google_Service_Calendar($client);
I have:
Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested
I don’t have admin.google access, I need to access only my own calendar and delete old events. Please let me know what I am missing.
thank you
Advertisement
Answer
I tried to recreate your case and i think i see what’s going wrong.
If you are picking “Web server”, when creating client configuration:
Then you can use php from example, run script, obtain access token from get variables and give it back to console:
However if you are creating client configuration and using “Web browser”, then your script is asking for redirect URI, which you can add to example php:
$client = new Google_Client();
$client->setRedirectUri('https://yourdomain.com/somedir');
$client->setApplicationName('Google Calendar API PHP Quickstart');
However then you have to go to Google Cloud Platform:
and authorize your domain and your redirect URI. When you run your script now, you will get your access token on redirect site.