【问题标题】:Reading from Google Sheet in Flutter / Dart在 Flutter / Dart 中阅读 Google 表格
【发布时间】:2019-06-03 02:50:26
【问题描述】:

我正在尝试在 Flutter 应用程序中读取和写入数据到谷歌表格,但我不知道该怎么做。我无法找到有关此问题的任何文档或示例。我对 Flutter / Dart 和 Google API 也很陌生,所以我真的不知道自己在做什么。

任何帮助将不胜感激!非常感谢。

【问题讨论】:

标签: google-sheets flutter dart google-api google-sheets-api


【解决方案1】:

以下是使用 googleapis 包从 Google 表格中读取电子表格的方法。请注意,这需要使用googleapis_auth 包进行身份验证。

Future readSpreadSheet() async {
  final httpClient = await clientViaApplicationDefaultCredentials(scopes: [
    StorageApi.devstorageReadOnlyScope,
  ]);
  try {
    final spreadsheetApi = SheetsApi(httpClient);
    spreadsheetApi.spreadsheets.get(spreadsheetId).then((Spreadsheet spreadsheet) {
      // Handle Spreadsheet
      // https://pub.dev/documentation/googleapis/latest/sheets.v4/Spreadsheet-class.html
    }).onError((error, stackTrace) {
      debugPrint('$error: $stackTrace');
    });
  } finally {
      httpClient.close();
  }
}

要获取spreadsheetId,您需要使用googleapis 包中的drive.v3 API。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-23
    • 2020-11-30
    相关资源
    最近更新 更多