Google 工作表 API v4 Flutter/Dart

Google Sheets API v4 for Flutter/Dart

是否会有 Google Sheets API v4 支持 Dart/Flutter, if yes when is it coming? It already has support for many languages but Dart/Flutter is not listed in their guides

googleapis package可在Flutter中使用,支持Sheets v4

另请参阅此

我创建了一个项目,为其启用了 sheets API,然后创建了一个 'robot-style' 服务帐户,并将密钥下载为 JSON。然后,我创建了一个 Google Sheet,并使其可公开访问,并注明其密钥。

此代码通过附加一行新数据连接并更新现有的 sheet。没有错误处理,但有一些 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?');

}

有一个 dart 第三方库可以帮助执行基本操作 https://pub.dev/packages/gsheets

也可以使用官方库https://pub.dartlang.org/packages/googleapis that helps to perform almost any operation, but it's more difficult to use and sometimes requires knowledge of the API https://developers.google.com/sheets/api/reference/rest