I am currently trying to use a service account to access the GoogleSheets API - the problem I encountered is related to my .json file.
Here is my code:
try
{
string[] scopes = new string[] { SheetsService.Scope.Spreadsheets, SheetsService.Scope.SpreadsheetsReadonly };
var stream = new FileStream("my_application_secret.json", FileMode.Open, FileAccess.Read);
var credential = GoogleCredential.FromStream(stream);
credential = credential.CreateScoped(scopes);
SheetsService service = new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "myApplication",
});
return service;
}
catch (Exception ex)
{
Console.WriteLine("Create service account myApplicationServiceAccount failed : " + ex.Message);
throw new Exception("Create ServiceAccount Failed : ", ex);
}
This will write off my error, which reads:
Create service account myApplicationServiceAccount failed : Error deserializing JSON credential data.
But all I can find on the Internet says that what I have above should work.
Is there anything else I have to do with this .json file?
Hanny source
share