I am testing the ability to get the shared link to a file so I can auto distribute it to users. Unfortunately, I am getting jibberish when making the request. Although the end goal is to feed a path\file and get the link in return, this is just a small step in the process. When I issue the getSharedLink call from the java API, I get:
com.box.sdk.BoxSharedLink@6b09bb57
When I go to the file through the UI and select "Copy Link" I get:
https://app.box.com/s/f44fuy1zrx59t2wkxvoka3kzxolrioqw
I would understand it more if the API result was some truncated version of the actual link, but it is not. Any assistance/suggestions would be most appreciated.
Note that I have also used the API to first create the link and then retrieve it and had the same results. The code is listed below, and the jars I use are (as suggested by Box documentation):
bcpkix-jdk15on-1.52.jar
bcprov-jdk15on-1.52.jar
box-java-sdk-2.14.1.jar
jose4j-0.4.4.jar
minimal-json-0.9.1.jar
Also:
commons-logging-1.2.jar
package getboxidandlink;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.box.sdk.*;
import com.box.sdk.BoxAPIConnection;
import com.box.sdk.BoxFolder;
import com.box.sdk.BoxUser;
/**
*
* @author saulf
*/
public class GetBoxIDandLink {
public static final String DEVELOPER_TOKEN = "";
public static final int MAX_DEPTH = 1;
public static void main(String[] args) {
// Turn off logging to prevent polluting the output.
Logger.getLogger("com.box.sdk").setLevel(Level.OFF);
BoxAPIConnection api = new BoxAPIConnection(DEVELOPER_TOKEN);
BoxUser.Info userInfo = BoxUser.getCurrentUser(api).getInfo();
System.out.format("Welcome, %s <%s>!\n\n", userInfo.getName(), userInfo.getLogin());
BoxFolder rootFolder = BoxFolder.getRootFolder(api);
listFolder(rootFolder, 0,DEVELOPER_TOKEN);
}
private static void listFolder(BoxFolder folder, int depth,String DEVELOPER_TOKEN) {
BoxAPIConnection api = new BoxAPIConnection(DEVELOPER_TOKEN);
for (BoxItem.Info itemInfo : folder) {
String indent = "";
for (int i = 0; i < depth; i++) {
indent += " ";
}
String fileType = String.valueOf(itemInfo.getClass());
fileType=fileType.substring(21,fileType.length()-5);
String fileID = String.valueOf(itemInfo.getID());
System.out.println(indent + itemInfo.getName()+" id:"+itemInfo.getID()+" class: "+fileType+" sharedLink: "+itemInfo.getSharedLink());
if (fileID.trim().equals("28***phone number removed for privacy***")) {
System.out.println(itemInfo.getName()+" is a file");
BoxFile file = new BoxFile(api, fileID);
Calendar unshareAt = Calendar.getInstance();
unshareAt.set(2100,12,31);
BoxSharedLink.Permissions permissions= new BoxSharedLink.Permissions();
permissions.setCanDownload(true);
permissions.setCanPreview(true);
//file.createSharedLink(BoxSharedLink.Access.OPEN,unshareAt.getTime(),permissions);
System.out.println(file.getInfo().getSharedLink());
}
//String astring = BoxSharedLink (api,itemInfo.getID());
if (itemInfo instanceof BoxFolder.Info) {
BoxFolder childFolder = (BoxFolder) itemInfo.getResource();
if (depth < MAX_DEPTH) {
listFolder(childFolder, depth + 1,DEVELOPER_TOKEN);
}
}
}
}
}