I\'m beating myself bloody trying to get a simple service acccount login to work in C#, to Google API and Google Analytics. My company is already getting data into Analytics, an
Another option is to use GoogleCredential.GetApplicationDefault(). I believe this is the currently (Oct. 2018) recommended approach. Here's some F#, but it's more or less the same in C# modulo syntax:
let projectId = ""
let creds =
GoogleCredential.GetApplicationDefault()
.CreateScoped(["https://www.googleapis.com/auth/cloud-platform"])
use service =
new CloudBuildService(
BaseClientService.Initializer(HttpClientInitializer=creds))
let foo = service.Projects.Builds.List(projectId).Execute()
Now, just make sure that you set the GOOGLE_APPLICATION_CREDENTIALS to point to the file with the credentials JSON file, eg. GOOGLE_APPLICATION_CREDENTIALS=creds.json dotnet run.