한국어 (korean) | English
purse fast, easy to use, intuitive API.
These are already included in gradle configuration file 'build.gradle'.
jar
files will be located on build/libs
after build
gradlew.bat build
./gradlew build
gradle build
You can see little bit more complicated examples in TestCode.java
Client
objectClient
object.Client
object.Client
object check expiration and refresh authorization automatically. but it can be done manually.Client
's constructor can obtain if you fallow OneDrive app instruction of authentication. import com.bhyoo.onedrive.client.Client;
String clientId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
String[] scope = {"files.readwrite.all", "offline_access"};
String redirectURL = "http://localhost:8080/";
String clientSecret = "xxxxxxxxxxxxxxxxxxxxxxx";
// with login
Client client = new Client(clientId, scope, redirectURL, clientSecret);
// without login
Client client = new Client(clientId, scope, redirectURL, clientSecret, false);
client.login();
// With tokens provided from outside source
String accessToken = "<access_token>";
String refreshToken = "<refresh_token>"
String tokenType = "bearer";
long expiresIn = 0;
Client client = new Client(clientId, scope, redirectURL, clientSecret, accessToken, refreshToken, tokenType, expiresIn);
FolderItem
and FileItem
are represent folder and file respectively.FolderItem
and FileItem
are child class of DriveItem
.import com.bhyoo.onedrive.container.items.DriveItem;
import com.bhyoo.onedrive.container.items.FileItem;
import com.bhyoo.onedrive.container.items.FolderItem;
// assume that Client object is already constructed
// get root directory
FolderItem root = client.getRootDir();
// get folder by ID
FolderItem folder = client.getFolder("XXXXXXXXXXXXXXXX!XXXX");
// get folder by path
FolderItem folder1 = client.getFolder(new PathPointer("/{item-path}"));
// get file by ID
FileItem file = client.getFile("XXXXXXXXXXXXXXXX!XXXX");
// get file by path
FileItem file1 = client.getFile(new PathPointer("/{item-path}/{file-name}"));
// or if you don't know whether ID is file or folder
DriveItem item = client.getItem("XXXXXXXXXXXXXXXX!XXXX");
// or if you don't know whether path is file or folder
DriveItem item1 = client.getItem(new PathPointer("/{item-path}"));
FolderItem
are Iterable
. (it will returns child as DriveItem
)FolderItem
object is fetched by Client
's method getFolder
or getRootDir
, the object automatically fetchs children too. (If children list is very long, it could take long time)FolderItem
's method getAllChildren
or getFolderChildren
or getFileChildren
, you can get List
of all children, only folder children, only file children respectively.import com.bhyoo.onedrive.container.items.DriveItem;
import com.bhyoo.onedrive.container.items.FileItem;
import com.bhyoo.onedrive.container.items.FolderItem;
// assume that Client object is already constructed
FolderItem root = client.getRootDir();
DriveItem[] children = root.allChildren();
FolderItem[] folderChildren = root.folderChildren();
FileItem[] fileChildren = root.fileChildren();
FolderItem
object or Client
object.FolderItem
object.import com.bhyoo.onedrive.container.items.FolderItem;
import com.bhyoo.onedrive.container.items.pointer.PathPointer;
// assume that Client object is already constructed
FolderItem root = client.getRootDir();
// create folder by parent folder object
FolderItem newFolder = root.createFolder("test");
// create folder by client with parent folder id
FolderItem newFolder1 = client.createFolder("XXXXXXXXXXXXXXXX!XXXX", "test1");
// create folder by client with parent folder path
FolderItem newFolder2 = client.createFolder(new PathPointer("/"), "test2");
Client
object.import com.bhyoo.onedrive.container.items.*;
import com.bhyoo.onedrive.container.items.pointer.*;
// assume that Client object is already constructed
FileItem item = (FileItem) client.getItem("XXXXXXXXXXXXXXXX!XXXX");
FolderItem destination = client.getFolder("XXXXXXXXXXXXXXXX!XXXX");
// direct copy
item.copyTo(destination);
// direct copy with new name
item.copyTo(destination, "newName");
// copy by reference object
item.copyTo(destination.newReference());
// copy by reference object with new name
item.copyTo(destination.newReference(), "newName");
// copy by path string
item.copyTo(destination.getPathPointer());
// copy by path string with new name
item.copyTo(destination.getPathPointer(), "newName");
// copy by id string
item.copyTo(destination.getId());
// copy by id string with new name
item.copyTo(destination.getId(), "newName");
// using `Client`, copy by path
client.copyItem(new PathPointer("/{item-path}"), new IdPointer("XXXXXXXXXXXXXXXX!XXXX"));
import java.nio.file.Paths;
import com.bhyoo.onedrive.container.items.FileItem;
// assume that Client object is already constructed
FileItem file = client.getFile("XXXXXXXXXXXXXXXX!XXXX");
String path = "/home/isac322/download";
// download by system path string with original file name
file.download(path);
// download by system path string with new name
file.download(path, "newName");
// download by path object with original file name
file.download(Paths.get(path));
// download by path object with new name
file.download(Paths.get(path), "newName");
client.download(new PathPointer("/{item-path}"), Paths.get(path));
DownloadFuture
will explain later at wiki...import java.nio.file.Paths;
import com.bhyoo.container.items.FileItem;
import com.bhyoo.network.async.DownloadFuture;
// assume that Client object is already constructed
FileItem file = client.getFile("XXXXXXXXXXXXXXXX!XXXX");
String path = "/home/isac322/download";
// download by path object with original file name
file.downloadAsync(Paths.get(path));
// download by path object with new name
file.downloadAsync(Paths.get(path), "newName");
DownloadFuture future = client.downloadAsync("{file-id}", Paths.get(path), "newName");
// wait until download is done
future.sync();
Client
object.import com.bhyoo.onedrive.container.items.FileItem;
import com.bhyoo.onedrive.container.items.FolderItem;
import com.bhyoo.onedrive.container.items.pointer.*;
// assume that Client object is already constructed
FileItem item = client.getFile("XXXXXXXXXXXXXXXX!XXXX");
FolderItem destination = client.getFolder("XXXXXXXXXXXXXXXX!XXXX");
// direct move
item.moveTo(destination);
// move by reference object
item.moveTo(destination.newReference());
// move by path string
item.moveTo(destination.getPathPointer());
// move by id string
item.moveTo(destination.getId());
// using `Client` object, move by folder path
client.moveItem(new PathPointer("/{item-path}"), new IdPointer("XXXXXXXXXXXXXXXX!XXXX"));
refresh
will update all variable with fetched latest metadata. refresh
is invoked, all variable can be changed, even if the current program did not modify the variables.import com.bhyoo.onedrive.container.items.DriveItem;
// assume that Client object is already constructed
DriveItem item = client.getItem("XXXXXXXXXXXXXXXX!XXXX");
// change item's name and flush to server.
item.rename("new name");
// change item's description and flush to server.
item.updateDescription("blah blah");
// refresh item's all variable to latest value
item.refresh();
UploadFuture
will explain later at wiki...import java.nio.file.Path;
import com.bhyoo.onedrive.network.async.UploadFuture;
// assume that Client object is already constructed
UploadFuture future;
// start to upload file
future = client.uploadFile("{remote-folder-id}", Paths.get("local-file-path"));
// wait until uploading is done
future.syncUninterruptibly();
*Item
diagram