Code Monkey home page Code Monkey logo

onedrive-java-client's Introduction

Java Client Library for OneDrive & OneDrive for Business REST APIs

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.

Build Status

Building

mvn clean install

Getting Started

Maven

To import the client as maven dependency, declare it as follow for latest release :

<dependency>
  <groupId>org.nuxeo.onedrive</groupId>
  <artifactId>onedrive-java-client</artifactId>
  <version>1.0</version>
</dependency>

If you want to use the on development version, declare :

<dependency>
  <groupId>org.nuxeo.onedrive</groupId>
  <artifactId>onedrive-java-client</artifactId>
  <version>1.1-SNAPSHOT</version>
</dependency>

Artifact is available in nuxeo repositories :

  • http://maven.nuxeo.org/nexus/content/groups/public
  • http://maven.nuxeo.org/nexus/content/groups/public-snapshot

OneDrive

To use the client with OneDrive you first need to create a OneDriveBasicApi to use it after with items of client :

OneDriveAPI api = new OneDriveBasicAPI("YOUR_ACCESS_TOKEN");

OneDrive for Business

To use the client with OneDrive for Business you need to create a OneDriveBusinessAPI to use it after with items of client :

OneDriveAPI 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.

First calls

Now you have your api object you can request the APIs, for example to get the root folder run :

OneDriveFolder root = OneDriveFolder.getRoot(api);

Or just get a folder or file item :

OneDriveFolder folder = new OneDriveFolder(api, "FOLDER_ID");
OneDriveFile file = new OneDriveFile(api, "FILE_ID");

Then retrieve the metadata :

OneDriveFolder.Metadata folderMetadata = folder.getMetadata();
OneDriveFile.Metadata fileMetadata = item.getMetadata();

Features

  • Iterate over folder children, to get all temporary download urls for example :
public List<String> getChildrenDownloadUrls(OneDriveFolder folder) {
    List<String> urls = new ArrayList<>();
    for (OneDriveItem.Metadata metadata : folder) {
        if (metadata.isFile()) {
            urls.add(metadata.asFile().getDownloadUrl());
        } else if (metadata.isFolder()) {
            urls.addAll(getChildrenDownloadUrls(metadata.asFolder().getResource()));
        }
    }
    return urls;
}
  • Download content of file :
InputStream stream = file.download();
  • Get ThumbnailSet :
Iterable<OneDriveThumbnailSet.Metadata> folderThumbnail = folder.getThumbnailSets();
OneDriveThumbnailSet.Metadata fileThumbnail = file.getThumbnailSet();
String smallUrl = fileThumbnail.getSmall().getUrl(); // Get the small thumbnail url
InputStream smallStream = fileThumbnail.getSmall().getResource().download(); // Download the content of small thumbnail

You can also request thumbnail this way :

OneDriveThumbnail thumbnail = new OneDriveThumbnail(api, "FILE_ID", OneDriveThumbnailSize.SMALL);
String smallUrl = thumbnail.getMetadata().getUrl();
InputStream smallStream = thumbnail.download();

Or while getting metadata with expand parameter :

OneDriveFile.Metadata metadata = file.getMetadata(OneDriveExpand.THUMBNAILS);
...
OneDriveThumbnailSet.Metadata fileThumbnail = metadata.getThumbnailSet();
  • Get email of current user : String email = OneDriveEmailAccount.getCurrentUserEmailAccount(api);

Limitations

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.

Licensing

Apache License, Version 2.0

About Nuxeo

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.

onedrive-java-client's People

Contributors

alivedevil avatar dkocher avatar kevinleturc avatar michaelva avatar atchertchian avatar nuxeojenkins avatar jcarsique avatar pgmillon avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.