2016-08-22 63 views
2

任何人都可以幫助我如何使用java SDK創建共享鏈接。我使用下面的代碼: -如何使用java sdk在框中創建共享鏈接

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); 

收到錯誤: -

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

回答

0

我剛剛通過了「零」的地方unsharedDate..I的我能得到一個共享鏈接。

BoxSharedLink sharedLink = file.createSharedLink( BoxSharedLink.Access.OPEN,null,permissions);

我不確定空值是什麼意思。我猜測,如果你傳遞null,沒有unsharedDate集合。找不到任何api文檔。

0
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; 
} 
相關問題