问题
Can any one help me on how to create shared link in BOX using java SDK. I am using below code:-
BoxFile file = new BoxFile(api, ID);
BoxSharedLink.Permissions permissions = new BoxSharedLink.Permissions();
permissions.setCanDownload(true);
permissions.setCanPreview(true);
Date unshareDate = new Date();
BoxSharedLink sharedLink = file.createSharedLink(
BoxSharedLink.Access.OPEN, unshareDate, permissions);
Getting error :-
The API returned the error code: 400
{"type":"error","status":400,"code":"bad_request","context_info":{"errors":[{"reason":"invalid_parameter","name":"unshared_at","message":"Invalid value '1471842735'."}]},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Bad Request","request_id":"208420399157ba89af5e170"}
回答1:
I just passed "null" in place of unsharedDate..I am able to get a shared link.
BoxSharedLink sharedLink = file.createSharedLink( BoxSharedLink.Access.OPEN, null, permissions);
I am not sure what null value means. I am guessing there is no unsharedDate set if you pass null. couldn't find any api documentation for this.
回答2:
private static BoxSharedLink createSharedLink(BoxAPIConnection api, String fileId) {
BoxFile file = new BoxFile(api, fileId);
BoxSharedLink.Permissions permissions = new BoxSharedLink.Permissions();
permissions.setCanDownload(true);
permissions.setCanPreview(true);
Date date = new Date();
Calendar unshareAt = Calendar.getInstance();
unshareAt.setTime(date);
unshareAt.add(Calendar.DATE, 14);
BoxSharedLink sharedLink = file.createSharedLink(BoxSharedLink.Access.COMPANY, unshareAt.getTime(), permissions);
logger.info("shared link: " + sharedLink.getURL());
return sharedLink;
}
来源:https://stackoverflow.com/questions/39072124/how-to-create-shared-link-in-box-using-java-sdk