Read the complete article on how to create and update folders using Microsoft Graph API in Java: https://blog.aspose.com/2022/04/14/manage-folders-with-microsoft-graph-api-java/
Last active
October 18, 2023 08:27
-
-
Save aspose-com-gists/e9851d09ebd67ccd725fa01a8ed0daef to your computer and use it in GitHub Desktop.
Create and Update Folders using Microsoft Graph API in Java
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 graph client | |
IGraphClient client = GraphClient.getClient(tokenProvider); | |
// Create folder | |
GraphFolderInfo newFolder = client.createFolder("TEST_FOLDER"); |
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 graph client | |
IGraphClient client = GraphClient.getClient(tokenProvider); | |
// Create folder inside inbox | |
GraphFolderInfo newFolder = client.createFolder(GraphKnownFolders.Inbox, "TEST_SUBFOLDER_1"); | |
// Create subfolder inside newly created folder | |
GraphFolderInfo inboxTestSubFolder2 = client.createFolder(newFolder.getItemId(), "TEST_SUBFOLDER_2"); |
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
ITokenProvider tokenProvider = new ITokenProvider() { | |
Date expirationDate = null; | |
@Override | |
public void dispose() { | |
} | |
@Override | |
public OAuthToken getAccessToken(boolean ignoreExistingToken) { | |
// Gets oAuth access token. | |
// If ignoreExistingToken is true, requests new token from a server. Otherwise behavior is depended on whether token exists or not. | |
// If token exists and its expiration date is not expired returns current token, otherwise requests new token from a server. | |
return null; | |
} | |
@Override | |
public OAuthToken getAccessToken() { | |
// Gets oAuth access token. | |
// If token exists and its expiration date is not expired returns current token, otherwise requests new token from a server. | |
return new OAuthToken("token", expirationDate); | |
} | |
}; |
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 graph client | |
IGraphClient client = GraphClient.getClient(tokenProvider); | |
// Get list of folders | |
GraphFolderInfoCollection folders = client.listFolders(); | |
// Loop through folders | |
for (GraphFolderInfo folderInfo : folders) { | |
if(folderInfo.getDisplayName()=="TEST_FOLDER") | |
{ | |
folderInfo.setDisplayName("NEW_TEST_FOLDER"); | |
// Update folder | |
GraphFolderInfo updatedFolder = client.updateFolder(folderInfo); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment