John Davidson

Client is unauthorized to retrieve access tokens using this method - Google calendar php api

0 comments
Message:


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 Google\Client();
$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



My Answer:
It seems like you are encountering authorization issues with your Google Calendar API integration. Here are a few things you can check and try to resolve the issue:

1. Make sure that you have correctly set up the service account and have downloaded the JSON key file. Double-check that the key file location is correct in your code.

2. Ensure that you have granted the necessary permissions to the service account for accessing your calendar. You can do this by sharing your calendar with the service account email address.

3. Check that you are using the correct calendar ID when setting the subject in your code. The calendar ID should be the email address associated with your Google Calendar.

4. Make sure that you have specified the correct scopes when setting up the client. The scope should be `Google_Service_Calendar::CALENDAR` for accessing calendar data.

5. If you are still facing issues, try regenerating the JSON key file and updating it in your code.

6. If you are using the service account, you do not need to set the access type to 'offline'. Remove the line `$client->setAccessType('offline');` from your code.

If you have followed these steps and are still facing issues, you may need to reach out to Google support for further assistance.

Rate this post

5 of 5 based on 9272 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us