How to create shared link in box using java sdk

2019-07-15 03:29发布

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"}

标签: java box-api box
2条回答
你好瞎i
2楼-- · 2019-07-15 03:57
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;
}
查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-07-15 04:02

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.

查看更多
登录 后发表回答