![](/img/trans.png)
[英]Accessing Google Spreadsheets with C# using Google Data API
[英]Google Sheets API, Get Spreadsheets for user in C#
我正在開發 Xamarin.Forms 應用程序,我想做的是:
目前,我知道谷歌用最新版本更新了很多他們的 API,我不能再使用SpreadsheetsService
。 我在官方文檔中看到的是他們正在使用SheetsService
,至少他們在這里是這樣。
這是我現在的代碼:
var service = new SheetsService(new BaseClientService.Initializer
{
HttpClientInitializer = this.userCredential,
ApplicationName = Statics.StaticStrings.AppDomain.ApplicationName
});
var spreadsheetId = "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms";
var range = "Class Data!A2:E";
SpreadsheetsResource.ValuesResource.GetRequest request = service.Spreadsheets.Values.Get(spreadsheetId, range);
到目前為止它是有效的,但我遇到的問題是,如果我有它的 ID,我可以得到電子表格,但我不確定從哪里可以得到它,當然我不想硬編碼它(使不感)。
this.userCredential
是來自Google.Apis.Auth.OAuth2.UserCredential
類型的Google.Apis.Auth.OAuth2.UserCredential
,我通過(IAuthorizationCodeFlow flow, string userId, TokenResponse token)
,因此在我傳遞令牌后,我希望我的用戶已經登錄。
我的問題是,如何獲取經過身份驗證的用戶獲得授權的所有電子表格,以便在此之后使用它們?
提前致謝!
Sheets API v4 不提供此特定操作。 這是為什么。
您可以使用 Google Drive API 的
https://developers.google.com/drive/v3/reference/#Files https://developers.google.com/drive/v3/reference/files/list
public IList<Google.Apis.Drive.v3.Data.File> GetAllFiles()
{
// Define parameters of request.
FilesResource.ListRequest listRequest = service.Files.List();
listRequest.PageSize = 10;
listRequest.Q = "mimeType='application/vnd.google-apps.spreadsheet'";
// List files.
return listRequest.Execute().Files;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.