Unable to create Service Account from JSON
See original GitHub issueThis is my code:
const string serviceAccountEmail = "...";
string[] scopes = { CalendarService.Scope.CalendarReadonly };
Stream stream = new FileStream(@"C:\...\console-generated-key.json", FileMode.Open, FileAccess.Read, FileShare.Read);
var credential = GoogleCredential.FromStream(stream);
credential.CreateScoped(scopes);
var service = new CalendarService(new BaseClientService.Initializer
{
HttpClientInitializer = credential,
ApplicationName = "My Application"
});
var request = service.Events.List("my-calendar@resource.calendar.google.com");
var events = request.Execute();
I get the following JSON back from googleapis.com:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
I’m able to authenticate with a .p12 for the same service account using:
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = scopes,
}.FromCertificate(certificate));
Related: #533
Issue Analytics
- State:
- Created 8 years ago
- Comments:16 (1 by maintainers)
Top Results From Across the Web
Create and delete service account keys | IAM Documentation
How to create and delete service account keys.
Read more >GCP - Service Account key - JSON download fails
Went to IAM & Admin -> Created a new service account -> created a key -> JSON -> The problem still persists. Use...
Read more >Create service accounts | IAM Documentation
This page explains how to create service accounts using the Identity and Access Management (IAM) API, the Google Cloud console, and the gcloud...
Read more >Create a service account - Google Workspace Admin Help
Create new key. Make sure the key type is set to JSON and click Create. You'll get a message that the service account's...
Read more >Google Service Account Json Problems - Builds
I'm trying to upload the Android APK to Google Play. I've created a google services account and given it the requested access.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@miguelRedit: Given that this issue is over 7 years old, I think it would be more productive to create a new issue with more details.
@miguelRedit: Again, please create a new issue rather than continuing to add things here. But I strongly suspect you’re not actually loading the JSON file you think you are… because assuming the
type
here is"service_account"
you wouldn’t get that error. In the new issue, please provide a complete example with a sample file - obviously not containing your actual credentials, but with all IDs/keys replaced by “xxx”.The error message you’re showing would happen if you had a JSON file which didn’t specify
type
at all. (The empty string before the period at the end is the type…)