java.lang.NoSuchMethodError: com.google.common.io.ByteStreams.exhaust(Ljava/io/InputStream;)J

With some IDE there’s a plugin to debug this kind of case. Anyway google-api-client 1.22.0, as you can see, depends on guava-jdk5 17. That version is in conflict with google-out-library.oath2-http that need version of guava > 20 Try to modify your pom.xml like this <dependency> <groupId>com.google.api-client</groupId> <artifactId>google-api-client</artifactId> <version>1.22.0</version> <exclusions> <exclusion> <groupId>com.google.guava</groupId> <artifactId>guava-jdk5</artifactId> </exclusion> </exclusions> </dependency> … Read more

Creating Google Calendar events with a GCP Service Account

Answer: You need to enable the APIs and provide scopes in three places: in your auth code, in the GCP console, and the Google Admin console. More Information: As I explained in the comments, the code you have provided should run without issue. The Insufficient Permission: Request had insufficient authentication scopes. error is a result … Read more

Can we access GMAIL API using Service Account?

I use the following C# code for accessing Gmail from Service Account String serviceAccountEmail = “999999999-9nqenknknknpmdvif7onn2kvusnqct2c@developer.gserviceaccount.com”; var certificate = new X509Certificate2( AppDomain.CurrentDomain.BaseDirectory + “certs//fe433c710f4980a8cc3dda83e54cf7c3bb242a46-privatekey.p12”, “notasecret”, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable); string userEmail = “[email protected]”; ServiceAccountCredential credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(serviceAccountEmail) { User = userEmail, Scopes = new[] { “https://mail.google.com/” } }.FromCertificate(certificate) ); if (credential.RequestAccessTokenAsync(CancellationToken.None).Result) { GmailService … Read more

Google OAuth using domain wide delegation and service account

Answer: You need to pass your Service Account private key obtained from the GCP console to your JWT Client, and specify which user you wish to impersonate as a subject. Code: After getting your private key, you need to pass this into your JWT Client before authorisation: let google = require(‘googleapis’); let privateKey = require(“./privatekey.json”); … Read more

Send mail via Google Apps Gmail using service account domain wide delegation in nodejs

So I was half-step close to the solution, the problem was that while creating const jwtClient = new google.auth.JWT(googleKey.client_email, null, googleKey.private_key, [‘https://www.googleapis.com/auth/gmail.send’], null); i did not mention the account to be impersonated. The correct initialization should be: const jwtClient = new google.auth.JWT(googleKey.client_email, null, googleKey.private_key, [‘https://www.googleapis.com/auth/gmail.send’], ‘[email protected]’); To summarize, the correct steps are: Created a project … Read more