I'm trying to create code in C# for accessing Google Calendar. In console.cloud.google.com I've enabled the API, added users en added the scopes shown in the image below. In my web application I've run Install-Package Google.Apis.Calendar.v3. In code, the following scopes are added String[] SCOPES = new String[] { "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/calendar", "https://www.googleapis.com/auth/calendar.events", }; I've code to create the credentials. UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(ASPxUploadControl1.UploadedFiles[0].FileContent).Secrets, SCOPES, UserId, CancellationToken.None, new FileDataStore(fileName, true)).Result; return credential; So far it works. I get an access token back and a refresh token. But if I try to do this CalendarList calendarList = this.service.CalendarList.List().Execute(); I get the following error: Google.GoogleApiException: 'The service calendar has thrown an exception. HttpStatusCode is Forbidden. Request had insufficient authentication scopes.' Error {Google.Apis.Requests.RequestError Request had insufficient authentication scopes. [403] Errors [ Message[Insufficient Permission] Location[ - ] Reason[insufficientPermissions] Domain[global] ] } Google.Apis.Requests.RequestError Can anyone help me with this?
It looks like the error is indicating that the authenticated user does not have the necessary permissions to access the calendar resource. You can try to update the scopes in your code to include the required permissions. In this case, you may need to add the `https://www.googleapis.com/auth/calendar.readonly` scope to allow read-only access to the user's calendars. You can update your `SCOPES` array to include the additional scope: String[] SCOPES = new String[] { "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/calendar", "https://www.googleapis.com/auth/calendar.events", "https://www.googleapis.com/auth/calendar.readonly", }; Code (markup): After updating the scopes, you will need to re-authorize the user with the updated permissions to generate a new access token with the correct scopes. Once you have updated the scopes and re-authorized the user, try to execute the `CalendarList.List()` method again to see if the error has been resolved.