【问题标题】:MS Graph API: Getting 404 when saving to _layouts folderMS Graph API:保存到 _layouts 文件夹时出现 404
【发布时间】:2021-02-01 10:01:33
【问题描述】:

我正在使用 MS Graph Java SDK 将文件保存到用户的 OneDrive 并在给定路径下:

@Test
public void createDriveItem() {
    String fileName = "moon.pdf";
    String fullPath = "a/_layouts/b" + fileName;
    byte[] content = Files.readAllBytes(Paths.get(fileName));
    graph.users(userId)
            .drive()
            .root()
            .itemWithPath(encodePath(fullPath))
            .content()
            .buildRequest()
            .put(content);
}

private String encodePath(String path) {
    String encoding = StandardCharsets.UTF_8.name();
    try {
        return URLEncoder.encode(path, encoding);
    } catch (UnsupportedEncodingException e) {
        return path;
    }
}

我正在使用 MS Graph Java SDK v2.5.0,Java 11。

但是,此请求失败并返回 404 : Not Found。如果我不对路径进行编码,它也会失败。它看起来像 /_layouts/ 这很麻烦,因为一旦我向它添加一些东西,请求就会起作用。

另外,我用多个帐户重现了这个错误。

我的问题是:这实际上是预期的吗?如果是,为什么通过 Web UI 完成创建相同的文件夹结构?

【问题讨论】:

  • 我没有使用 Sdk,但我尝试直接使用 Graph API,它对我有用(使用 POSTMAN/Graph explorer)。你也试过了吗?这将帮助您隔离问题。也尝试使用最新的 SDK,看看你是否也能重现这个问题

标签: java sdk microsoft-graph-api


【解决方案1】:

我认为您应该无法将项目添加到 SharePoint Online 上的 /_layouts/ 中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-01
    • 2022-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多