Android Google表格API V4 - 更新没有OAuth的公开表格 [英] Android Google Sheets API V4 - Update public sheet without OAuth
问题描述
我正在尝试通过API以编程方式更新公共电子表格(设置为任何人都可以编辑),但它失败了
I'm trying to programmatically update a public spreadsheet (set to anyone can edit) via the API but it fails with
401 - 请求没有有效的身份验证凭据。
401 - "The request does not have valid authentication credentials."
我希望不需要有效身份验证凭据,因为它是公开的可编辑的电子表格。我可以从表单中获取数据,但我必须生成浏览器API密钥,因为显然使用Android密钥不起作用。
I would expect to not need "valid authentication credentials" since it's a publicly editable spreadsheet. I can GET data from the sheet just fine, although I had to generate a "browser" API Key since apparently using an Android Key doesn't work.
任何人都知道如果有一个技巧可以使更新工作,或者这是不可能的API?
Anyone know if there is a trick to getting an update to work, or is this not possible with the API?
示例代码我一起黑客攻击:
Sample code I'm hacking together:
// Don't think I even need this?
GoogleCredential credential = new GoogleCredential();
credential.createScoped(Collections.singleton(SheetsScopes.SPREADSHEETS));
HttpTransport transport = AndroidHttp.newCompatibleTransport();
JsonFactory factory = JacksonFactory.getDefaultInstance();
final Sheets sheets = new Sheets.Builder(transport, factory, credential)
.setApplicationName("My Awesome App")
.build();
final String sheetID = "[ID Of Valid Public Spreadsheet Here]";
final String range = "A:S";
final ValueRange content = new ValueRange();
content.set("Column A Name", "Some Value to Set");
new Thread() {
@Override
public void run() {
try {
UpdateValuesResponse valueRange = sheets.spreadsheets().values()
.update(sheetID, range, content)
.setKey("My-Valid-Browser-Api-Key")
.execute();
mLog.D("Got values: " + valueRange);
}
catch (IOException e) {
mLog.E("Sheets failed", e);
}
}
}.start();
推荐答案
今天的Sheets V4 API不允许进行匿名编辑,即使是允许它的床单。 (它允许对允许它的表格进行匿名读取。)
The Sheets V4 API today does not allow anonymous edits, even for sheets that allow it. (It does allow anonymous reads for sheets that allow it.)
这篇关于Android Google表格API V4 - 更新没有OAuth的公开表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!