Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drives SDK - Get Items Children Not working #2123

Closed
kosik opened this issue Aug 16, 2024 · 4 comments
Closed

Drives SDK - Get Items Children Not working #2123

kosik opened this issue Aug 16, 2024 · 4 comments
Labels
no-recent-activity status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question

Comments

@kosik
Copy link

kosik commented Aug 16, 2024

Describe the bug

Here is the link to official documentation: driveitem-list-children

Here is the code snippet from there:

// Code snippets are only available for the latest version. Current version is 6.x GraphServiceClient graphClient = new GraphServiceClient(requestAdapter); DriveItemCollectionResponse result = graphClient.drives().byDriveId("{drive-id}").items().byDriveItemId("{driveItem-id}").children().get();

The documentation states if pass "root" into byDriveItemId method, the SDK will return the list items of the root directory. In fact this method returns empty collection.

I verified if the API works with plain HTTP invocation through MS Graph Explorer, and there are many items in response. So I have took one of the identifiers from the response manually and put it into byDriveItemId. The API returned com.microsoft.graph.models.odataerrors.ODataError: The resource could not be found. I anticipated to see the list of files inside the directory of the root drive.

As you see the sample from official Java SDK documentation does not working. I start guessing and attempted other variants to let the SDK works but did not succeed.

Could you please provide a working code snippet allowing to receive a list of files of a given URL in a shared directory or fix the BUG.

Belowe I am attaching my code, configurations and more details:

https://login.microsoftonline.com/_my-ID-here_/oauth2/v2.0/authorize?client_id=XXX&response_type=code&redirect_uri=https://my-domain.com/az-token&response_mode=query&scope=https://graph.microsoft.com/Files.Read.All User.Read offline_access Sites.Read.All&

` private String[] scopes = new String[]{"Files.Read.All", "User.Read", "offline_access", "Sites.Read.All"};

public void getData(final String code){
    List<DriveItem> rootItems = getGraphClient(code).drives()
            .byDriveId(myDriveId).items().byDriveItemId("root").children().get().getValue();
    rootItems.size();
}


private GraphServiceClient getGraphClient(final String authorizationCode) {
    if(null == authorizationCode)
        throw new DomainException(ErrorCodes.InvalidInput, "msgraph-pkce-code-required");

    GraphServiceClient graphClient = null;
    if (null == graphClient) {
        final AuthorizationCodeCredential credential = new AuthorizationCodeCredentialBuilder()
                .clientId(CLIENT_APP_ID).tenantId(TENANT_ID).clientSecret(CLIENT_APP_SECRET)
                .authorizationCode(authorizationCode).redirectUrl(AUTH_REDIRECT_URL).build();

        if (null == scopes || null == credential) {
            throw new DomainException(ErrorCodes.InvalidInput, "msgraph-initialization-error-00");
        }

        graphClient = new GraphServiceClient(credential, scopes);
    }
    return graphClient;
}`

Thank you in advance.

Expected behavior

to see the list of files inside the directory of the root drive.

How to reproduce

I have configured the required permissions in Azure portal for my application: Files.Read.All User.Read offline_access Sites.Read.All

After this a put the below URL into browser location string. Which lead to login and passing the token into my application controller. The getData(final String code){ received the code and passed authorization successfully. Nevertheless, the subsequent Children Items list API execution does not working even with the example from official documentation code snippet.

https://login.microsoftonline.com/_my-ID-here_/oauth2/v2.0/authorize?client_id=XXX&response_type=code&redirect_uri=https://my-domain.com/az-token&response_mode=query&scope=https://graph.microsoft.com/Files.Read.All User.Read offline_access Sites.Read.All&

SDK Version

6.13.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

No response

Configuration

No response

Other information

JDK 21

@kosik kosik added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Aug 16, 2024
@Ndiritu
Copy link
Contributor

Ndiritu commented Aug 16, 2024

Hi @kosik, unfortunately I'm unable to reproduce this behavior. Are you able to double-check that you're using the right drive ID?

@Ndiritu Ndiritu added type:question An issue that's a question and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Aug 16, 2024
@kosik
Copy link
Author

kosik commented Aug 16, 2024

@Ndiritu thank you for the answer.
The driveId is correct for sure, the value in myDriveId variable is my drive identifier.

@Ndiritu
Copy link
Contributor

Ndiritu commented Aug 19, 2024

@kosik please clarify what request you tested on Graph Explorer: /drives/{drive-id}/items/root/children?
From your description it seems that this is the URL you called & that you used an ID from one of the results as your new "drive ID"?

@Ndiritu Ndiritu added the status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close label Sep 23, 2024
Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-recent-activity status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question
Projects
None yet
Development

No branches or pull requests

2 participants