Ce service de Google sont abandonnées et maintenant ils sont venus avec un autre nom services Google.Apis.Sheets.v4.
donc le code ci-dessus ne fonctionnera pas maintenant quelques jours, j'ai déjà essayé.
Et trouvez quelque chose qui a fonctionné pour moi.
J'ai écrit un blog et partagé le code source entier là. Vérifiez-le.
private static SheetsService AuthorizeGoogleApp()
{
UserCredential credential;
using (var stream =
new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/sheets.googleapis.com-dotnet-quickstart.json");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
}
// Create Google Sheets API service.
var service = new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
return service;
}
Pour tout le code source, vérifiez-le. Insérer une nouvelle ligne dans Google Sheet à l'aide de Google.Apis.Sheets.V4 Services