尝试使用 MSGraph v6 for Java 将元数据添加到 Sharepoint 中的文件时出错

问题描述 投票:0回答:1

我在共享点中有一个文件(我知道 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)

还有其他方法可以实现吗?

java sharepoint microsoft-graph-api microsoft-graph-sdks
1个回答
0
投票

我认为您需要更新与

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);;
© www.soinside.com 2019 - 2024. All rights reserved.