【问题标题】:Google Sheets API v4 for Flutter/Dart用于 Flutter/Dart 的 Google Sheets API v4
【发布时间】:2018-03-10 00:51:39
【问题描述】:

Google Sheets API v4 是否支持Dart/Flutter,如果支持,什么时候支持?它已经支持多种语言,但 Dart/Flutter 未在其guides 中列出。

【问题讨论】:

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


    【解决方案1】:

    googleapis package 可用于 Flutter 并支持 Sheets v4

    另请参阅similar Stack Overflow question

    【讨论】:

    • 谢谢甘特。可惜 dartlang google apis 的例子不多,google sheet api 的例子也没有。
    • 是的,但其他语言的示例应该不会太难转换。如果您遇到问题,只需发布​​一个问题。
    【解决方案2】:

    有一个 dart 3rd 方库,可帮助执行基本操作https://pub.dev/packages/gsheets

    您也可以使用官方库https://pub.dartlang.org/packages/googleapis,这有助于执行几乎所有操作,但使用起来比较困难,有时需要了解 API https://developers.google.com/sheets/api/reference/rest

    【讨论】:

      【解决方案3】:

      我创建了一个项目,为其启用了工作表 API,然后创建了一个“机器人风格”服务帐户,并将密钥下载为 JSON。然后,我创建了一个 Google 表格,并将其公开,并注明其密钥。

      此代码通过附加一行新数据来连接和更新现有工作表。没有错误处理,但一些 print() 语句有助于可视化流程。

      // Key for service account copied from downloaded file for demo purposes ;-)
      final _key = {
        "type": "service_account",
        "project_id": //etc
        // ...
        // ...
      };
      
      print('getting oauth');
      auth
          .obtainAccessCredentialsViaServiceAccount(
              auth.ServiceAccountCredentials.fromJson(_key),
              scopes,
              http.Client())
          .then((auth.AccessCredentials cred) {
        print('got oauth');
      
        auth.AuthClient client = auth.authenticatedClient(http.Client(), cred);
        SheetsApi api = new SheetsApi(client);
        ValueRange vr = new ValueRange.fromJson({
          "values": [
            [ // fields A - J
              "15/02/2019", "via API 3", "5", "3", "3", "3", "3", "3", "3", "3"
            ]
          ]
        });
        print('about to append');
        api.spreadsheets.values
            .append(vr, '1cl...spreadsheet_key...W5E', 'A:J',
                valueInputOption: 'USER_ENTERED')
            .then((AppendValuesResponse r) {
          print('append completed.');
          client.close();
        });
        print('called append()');
      });
      print('ended?');
      

      }

      【讨论】:

      猜你喜欢
      • 2016-10-13
      • 2018-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多