javamicrosoft-graph-apimicrosoft-graph-sdksmicrosoft-graph-files

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


I build 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();

and I try to find a file

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

but receive 403 HTTP status, is it a problem in scope or file permissions?

UDP: I also try with

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

Response:

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

Solution

  • Need to add the scope "Sites.Read.All" before the update I had "User.Read.All" and "Files.Read.All"