Skip to content

Instantly share code, notes, and snippets.

@maisarissi
Last active December 12, 2023 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maisarissi/c83eb0c87006790e6524d019e0b92c28 to your computer and use it in GitHub Desktop.
Save maisarissi/c83eb0c87006790e6524d019e0b92c28 to your computer and use it in GitHub Desktop.
microsoftgraph-java-v6-pagination
// Get the messages
MessageCollectionResponse messages = graphClient.me().messages().get();
// Instantiate collection to store all messgaes
List<Message> messagesList = new LinkedList<Message>();
// Configure iterator
PageIterator iterator = new PageIterator.Builder<Message, MessageCollectionResponse>()
.client(graphClient)
.collectionPage(messages)
// Type of response expected for each page
.collectionPageFactory(MessageCollectionResponse::createFromDiscriminatorValue)
// Callback on how to handle each message encountered
.processPageItemCallback(message -> {
messagesList.add(message);
return true; })
.build();
iterator.iterate();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment