如何在Google Drive api v3中使用appProperties? [英] How to use appProperties in Google Drive api v3?
问题描述
如何在java中使用Google Drive v3设置文件的应用程序属性?
引用说:files.update with {'appProperties':{' key':'value'}},但我不明白如何将它应用到我的java代码中。
我试过类似
$ b
file = service.files()。create(body).setFields(id)。execute();
Map< String,String> properties = new HashMap<>();
properties.put(DEVICE_ID_KEY,deviceId);
file.setAppProperties(properties);
service.files()。update(file.getId(),file).setFields(appProperties)。execute();
但是我得到一个错误:资源正文包含不能直接写入的字段。
获取数据:
文件fileProperty =服务。 。文件()得到(sFileId).setFields( appProperties)执行()。
那么如何设置和获取文件的属性呢?
谢谢! :)
编辑
我试过了
file = service.files()。create(body).setFields(id)。execute();
Map< String,String> properties = new HashMap<>();
properties.put(DEVICE_ID_KEY,deviceId);
file.setAppProperties(properties);
service.files()。update(file.getId(),file).execute();
但我仍然收到相同的错误讯息。
在v3上避免出现此错误
资源正文包含字段不能直接写入。
在调用 update
时,您需要创建一个空的 File
与新的更改并将其传递给 update
函数。
我在此处撰写了 v3迁移指南 。
How to set the app properties of a file using Google Drive v3 in java?
The reference says: "files.update with {'appProperties':{'key':'value'}}", but I don't understand how to apply that to my java code.
I've tried things like
file = service.files().create(body).setFields("id").execute();
Map<String, String> properties = new HashMap<>();
properties.put(DEVICE_ID_KEY, deviceId);
file.setAppProperties(properties);
service.files().update(file.getId(), file).setFields("appProperties").execute();
but then I get an error that "The resource body includes fields which are not directly writable."
And to get the data:
File fileProperty = service.files().get(sFileId).setFields("appProperties").execute();
So how to set and get the properties for the file? Thanks! :)
Edit I tried
file = service.files().create(body).setFields("id").execute();
Map<String, String> properties = new HashMap<>();
properties.put(DEVICE_ID_KEY, deviceId);
file.setAppProperties(properties);
service.files().update(file.getId(), file).execute();
but I still get the same error message.
To avoid this error on v3
"The resource body includes fields which are not directly writable."
when calling update
, you need to create an empty File
with the new changes and pass that to the update
function.
I wrote this and other notes as a v3 Migration Guide here.
这篇关于如何在Google Drive api v3中使用appProperties?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!