從谷歌這一服務被停用,現在他們想出了另外一個名爲Google.Apis.Sheets.v4服務。
所以上面的代碼現在不行,現在我已經試過了。
並找到適合我的東西。
我已經寫了一篇博客,並在那裏分享了整個源代碼。一探究竟。
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;
}
對於整個源代碼檢查出來。使用Google.Apis.Sheets.V4服務向Google圖表插入新行