簡體   English   中英

我在“/drive/root/search(q='file-name')”上收到 403 HTTP 狀態

[英]I receive 403 HTTP status on "/drive/root/search(q='file-name')"

我建立 GraphServiceClient

        final ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
            .clientId("todo-replace-on-own")
            .clientSecret("todo-replace-on-own")
            .tenantId("todo-replace-on-own")
            .build();

        final TokenCredentialAuthProvider tokenCredAuthProvider =
            new TokenCredentialAuthProvider(List.of("https://graph.microsoft.com/.default"), clientSecretCredential);

        final GraphServiceClient graphClient = GraphServiceClient
            .builder()
            .authenticationProvider(tokenCredAuthProvider)
            .buildClient();

我試圖找到一個文件

graphClient.customRequest("/drive/root/search(q='file-name')")
    .buildRequest()
    .get();

但收到 403 HTTP 狀態,是 scope 還是文件權限的問題?

UDP:我也嘗試使用

        DriveItemSearchCollectionPage search = graphClient
            .drive()
            .root()
            .search(DriveItemSearchParameterSet.newBuilder() .withQ("File_Name").build())
            .buildRequest()
            .get();

回復:

Error message: Access denied

GET https://graph.microsoft.com/v1.0/drive/root/microsoft.graph.search(q='File_Name')
SdkVersion : graph-java/v5.31.0


403 : Forbidden

看起來您正在嘗試使用錯誤的代碼。 使用此代碼搜索文件:

GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();

DriveItemSearchCollectionPage search = graphClient.me().drive().root()
    .search(DriveItemSearchParameterSet
        .newBuilder()
        .withQ("File_Name")
        .build())
    .buildRequest()
    .get();

參考: https://docs.microsoft.com/en-us/graph/api/driveitem-search?view=graph-rest-1.0&tabs=java

需要在更新之前添加 scope “Sites.Read.All” 我有“User.Read.All”和“Files.Read.All”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM