Google 张 API V4 阅读 public sheet 少步骤

Google Sheets API V4 for reading public sheet with less steps

我们想提供 public 表格中的参考列表,每个人都可以在 android 中查看。 我试过 Quickstart sample from Google 效果很好。

但我们希望尽量减少这些步骤(例如允许访问联系人、选择 google 帐户等步骤),因为此应用程序专为考虑自杀的人设计。该列表包含有关在哪里寻求帮助的信息。

我找到了a article about how to read a sheet as a InputStream

如果 Google Sheet API V4

有更优雅的方式,我将不胜感激

如果表格共享给 "anyone with link" 或 "public",可能不需要在 Android 中完成帐户流程。选择一个帐户主要是为了获得正确的凭据,但是 public 工作表可以使用 API.

匿名阅读(没有凭据)

如果您仍在寻找答案,只需替换一行即可:

Credential credential = new GoogleCredential().createScoped(SCOPES);

而不是

Credential credential = authorize();

那么就可以去掉方法authorize()和对应的变量

我发现 com.google.api.services.sheets.v4.Sheets 中有一个 setKey 方法。对于Builder中的第三个参数,作为凭证,可以为空。但是,如果 Key 限制为 Android,则会出现错误 "Requests from this Android client application are blocked"。