OneDrive / onedrive-sdk-csharp

OneDrive SDK for C#! https://dev.onedrive.com
Other
293 stars 143 forks source link

How can I "page" my request? #199

Closed assassin316 closed 8 years ago

assassin316 commented 8 years ago

I have the following code in which I want to get 20 child items at a time:

    var expandString = _client.AuthenticationProvider is MsaAuthenticationProvider
                                ? "thumbnails, children(expand=thumbnails)"
                                : "thumbnails, children";

    var options = new List<Option>
    {
        new QueryOption("top", "20")
    };

    var item = await _client.Drive
                    .Items[id]
                    .Request(options)
                    .Expand(expandString)
                    .GetAsync(ct);

    // Get the "next" request for paging purposes (if it exists)
    _nextItemRequest = item.Children.NextPageRequest;

        var items = item.Children == null
            ? new List<Item>()
            : item.Children.CurrentPage.Where(child => child.Photo != null);

But I receive the following error in Fiddler:

 The query specified in the URI is not valid. The requested resource is not a collection. Query options $filter, $orderby, $count, $skip, and $top can be applied only on collections.

What am I doing wrong?

cdmayer commented 8 years ago

The error message says that query options can only be applied to collections. You requested Items[id] which will return one item. Were you trying to get the children of that item? If so, try this request:

var item = await _client.Drive
    .Items[id]
    .Children
    .Request(options)
    .Expand(expandString)
    .GetAsync(ct);
assassin316 commented 8 years ago

Works like a charm!! :) Thanks.