我在共享点中有一个文件(我知道 DriveItemId),我想向其中添加元数据(比如说标题)。为此,我使用 MS Graph SDK for Java (6.3.0)。我尝试这样做:
GraphServiceClient client = .... ;
Map<String, Object> metadata=... ;
...
final DriveItem driveItem = client.drives().byDriveId(<parent_folder_id>).items().byDriveItemId(driveItemId).get();
driveItem.setAdditionalData(metadata);
client.drives().byDriveId(<parent_folder_id>).items().byDriveItemId(driveItemId).patch(driveItem);
但是执行“patch”时出现错误:
com.microsoft.graph.models.odataerrors.ODataError: Invalid request
at com.microsoft.graph.models.odataerrors.ODataError.createFromDiscriminatorValue(ODataError.java:36)
at com.microsoft.kiota.serialization.JsonParseNode.getObjectValue(JsonParseNode.java:210)
at com.microsoft.kiota.http.OkHttpRequestAdapter.lambda$throwIfFailedResponse$0(OkHttpRequestAdapter.java:672)
还有其他方法可以实现吗?
我认为您需要更新与
fields
关联的
listItem
上的
driveItem
// get the listItem associated with the driveItem
final ListItem listItem = graphClient.drives().byDriveId("").items().byDriveItemId("").listItem().get();
// prepare fieldValueSet to be updated
FieldValueSet fieldValueSet = new FieldValueSet();
HashMap<String, Object> additionalData = new HashMap<String, Object>();
additionalData.put("Title", "New value");
fieldValueSet.setAdditionalData(additionalData);
// read sharepoint ids
SharepointIds sharepointIds = listItem.getSharepointIds();
// update fields of the listItem associated with the driveItem
graphClient.sites().bySiteId(sharepointIds.getSiteId()).lists().byListId(sharepointIds.getListId()).items().byListItemId(listItem.getId()).fields().patch(fieldValueSet);;