Name: onedrive-java-client
Owner: Nuxeo
Description: Java client for OneDrive & OneDrive for Business
Created: 2016-02-04 14:10:24.0
Updated: 2018-03-20 20:53:58.0
Pushed: 2016-08-24 14:55:54.0
Size: 59
Language: Java
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
The OneDrive & OneDrive for Business Java Client is a Java client library for REST API. It is designed to work with both OneDrive & OneDrive for Business and to have light dependencies.
mvn clean install
To import the client as maven dependency, declare it as follow for latest release :
endency>
roupId>org.nuxeo.onedrive</groupId>
rtifactId>onedrive-java-client</artifactId>
ersion>1.0</version>
pendency>
If you want to use the on development version, declare :
endency>
roupId>org.nuxeo.onedrive</groupId>
rtifactId>onedrive-java-client</artifactId>
ersion>1.1-SNAPSHOT</version>
pendency>
Artifact is available in nuxeo repositories :
http://maven.nuxeo.org/nexus/content/groups/public
http://maven.nuxeo.org/nexus/content/groups/public-snapshot
To use the client with OneDrive you first need to create a OneDriveBasicApi
to use it after with items of client :
riveAPI api = new OneDriveBasicAPI("YOUR_ACCESS_TOKEN");
To use the client with OneDrive for Business you need to create a OneDriveBusinessAPI
to use it after with items of client :
riveAPI api = new OneDriveBusinessAPI("YOUR_RESOURCE_URL", "YOUR_ACCESS_TOKEN");
YOUR_RESOURCE_URL
corresponds to your sharepoint resource url provided by microsoft, for example : https://nuxeofr-my.sharepoint.com
.
Now you have your api
object you can request the APIs, for example to get the root folder run :
riveFolder root = OneDriveFolder.getRoot(api);
Or just get a folder or file item :
riveFolder folder = new OneDriveFolder(api, "FOLDER_ID");
riveFile file = new OneDriveFile(api, "FILE_ID");
Then retrieve the metadata :
riveFolder.Metadata folderMetadata = folder.getMetadata();
riveFile.Metadata fileMetadata = item.getMetadata();
Iterate over folder children, to get all temporary download urls for example :
ic List<String> getChildrenDownloadUrls(OneDriveFolder folder) {
<String> urls = new ArrayList<>();
(OneDriveItem.Metadata metadata : folder) {
if (metadata.isFile()) {
urls.add(metadata.asFile().getDownloadUrl());
} else if (metadata.isFolder()) {
urls.addAll(getChildrenDownloadUrls(metadata.asFolder().getResource()));
}
rn urls;
Download content of file :
tStream stream = file.download();
Get ThumbnailSet :
able<OneDriveThumbnailSet.Metadata> folderThumbnail = folder.getThumbnailSets();
riveThumbnailSet.Metadata fileThumbnail = file.getThumbnailSet();
ng smallUrl = fileThumbnail.getSmall().getUrl(); // Get the small thumbnail url
tStream smallStream = fileThumbnail.getSmall().getResource().download(); // Download the content of small thumbnail
You can also request thumbnail this way :
riveThumbnail thumbnail = new OneDriveThumbnail(api, "FILE_ID", OneDriveThumbnailSize.SMALL);
ng smallUrl = thumbnail.getMetadata().getUrl();
tStream smallStream = thumbnail.download();
Or while getting metadata with expand
parameter :
riveFile.Metadata metadata = file.getMetadata(OneDriveExpand.THUMBNAILS);
riveThumbnailSet.Metadata fileThumbnail = metadata.getThumbnailSet();
Get email of current user :
Currently the OneDrive Java Client doesn't provide OAuth support to obtain or refresh an access token. You might obtain one before using the client.
Nuxeo dramatically improves how content-based applications are built, managed and deployed, making customers more agile, innovative and successful. Nuxeo provides a next generation, enterprise ready platform for building traditional and cutting-edge content oriented applications. Combining a powerful application development environment with SaaS-based tools and a modular architecture, the Nuxeo Platform and Products provide clear business value to some of the most recognizable brands including Verizon, Electronic Arts, Sharp, FICO, the U.S. Navy, and Boeing. Nuxeo is headquartered in New York and Paris. More information is available at www.nuxeo.com.