This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
repositories { | |
// Use Maven Central for resolving dependencies. | |
mavenCentral() | |
// Add sonatype repository | |
maven { | |
url 'https://oss.sonatype.org/content/repositories/snapshots/' | |
} | |
} | |
dependencies { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final String[] scopes = new String[] {"Mail.Read", "Mail.Send", "User.Read"}; | |
final String[] allowedHosts = new String[] {"graph.microsoft.com"}; | |
DeviceCodeCredential deviceCodeCredential = new DeviceCodeCredentialBuilder() | |
.clientId(appId) | |
.tenantId(tenantId) | |
.challengeConsumer(challenge -> { | |
System.out.println(challenge.getMessage()); | |
}) | |
.build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DeviceCodeCredential deviceCodeCredential = new DeviceCodeCredentialBuilder() | |
.clientId(clientId) | |
.tenantId(tenantId) | |
.challengeConsumer(challenge -> System.out.println(challenge.getMessage())) | |
.build(); | |
//create a client for calling v1.0 endpoint | |
com.microsoft.graph.serviceclient.GraphServiceClient graphClient = | |
new com.microsoft.graph.serviceclient.GraphServiceClient( | |
deviceCodeCredential, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Use adjusted pageIterator sample from above to get list of first 100 messageIds. | |
MessageCollectionResponse messages = graphClient | |
.me() | |
.messages() | |
.get(); | |
List<String> messagesIdList = new LinkedList<String>(); | |
PageIterator pageIterator = new PageIterator.Builder<Message, MessageCollectionResponse>() | |
.client(graphClient) | |
.collectionPage(messages) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get the object | |
Event event = graphClient | |
.me() | |
.events() | |
.byEventId("event-id") | |
.get(); | |
// the backing store will keep track that the property change and send the updated value. | |
event.setRecurrence(null); // set to null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User user = new User(); | |
user.setDisplayName("displayName"); | |
user.setMail("[email protected]"); | |
graphClient | |
.users() | |
.post(user); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User user = new User(); | |
user.displayName = "displayName"; | |
user.userPrincipalName = "[email protected]"; | |
graphClient | |
.users() | |
.buildRequest() | |
.post(user); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int memberCount = graphClient | |
.groups() | |
.byGroupId("Id") | |
.members() | |
.graphUser() | |
.count() //Where applicable to enable the use of $count | |
.get(requestConfiguration -> { | |
requestConfiguration.headers.add("ConsistencyLevel", "Eventual"); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UserCollectionResponse response = graphClient | |
.groups() | |
.byGroupId("Id") | |
.members() | |
.graphUser() | |
.get( requestConfiguration -> { | |
requestConfiguration.headers.add("ConsistencyLevel", "Eventual"); | |
requestConfiguration.queryParameters.top = 10; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Fetching the members of a group who are of the type User | |
//graph.microsoft.com/v1.0/groups/{group-id}/members/microsoft.graph.user | |
UserCollectionResponse usersInGroup = graphClient | |
.groups() | |
.byGroupId("group-id") | |
.members() | |
.graphUser() | |
.get(); | |
List<User> users = usersInGroup.getValue(); |
NewerOlder