2

I am trying to access google-calendar with the help of google service account but i got belloing error

An exception of type 'Google.Apis.Auth.OAuth2.Responses.TokenResponseException' occurred in Google.Apis.dll but was not handled in user code

The error I am getting: "invalid_grant", Description:"Invalid JWT: Token must be a short-lived token and in a reasonable timeframe", Uri:""

        string credPath = "key path";

        String serviceAccountEmail = xxxx@developer.gserviceaccount.com";

        var certificate = new X509Certificate2(credPath, "notasecret", X509KeyStorageFlags.Exportable);

        ServiceAccountCredential credential = new ServiceAccountCredential(
           new ServiceAccountCredential.Initializer(serviceAccountEmail)
           {
               Scopes = new[] {  CalendarService.Scope.CalendarReadonly,
                                CalendarService.Scope.Calendar}
           }.FromCertificate(certificate));

        // Create the service.
        var service = new CalendarService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "HRTool",
        });


        var events = service.Events.List("my calaender id").Execute();
Pramod Gehlot
  • 319
  • 2
  • 4
  • 17

3 Answers3

13

Invalid grant

When you try to use a refresh token, the following returns you an invalid_grant error:

First, kindly check the synchronization problem with the server clock, see the poor synchronization of the computer's clock answer for additional information. Second, check handling of refresh token and the old tokens. Some flows include additional steps, such as using refresh tokens to acquire new access tokens. For detailed information about flows for various types of applications, see Google's OAuth 2.0 documentation.

Hope this helps!

Community
  • 1
  • 1
Mr.Rebot
  • 6,703
  • 2
  • 16
  • 91
0

If you are getting the error of "Invalid JWT Signature." and if you are using the P12 certificate then confirm the P12 is correct or not for the Client Key you have used.

0

If you are getting the error of "Invalid JWT Signature." This is the error caused by some other plugin which you just installed check. I solved by removing rank math plugin as after this plugin install the elementor update was not working.