cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get ( I don't want to create it ) the link of a file or folder if it does exist already.

Get ( I don't want to create it ) the link of a file or folder if it does exist already.

Aldo M.2
New member | Level 1

Hi,

I am buildng an app in Java Dropbox API V2 that would display for each file or folder a link only if the owner has created a link for it.

The application is this application screenshot.

I'll explain better now.
I know it's possible to create from the dropbox.com website a link for any of the items create a link screenshot.

without specifying any email address to who I am sharing the file with anyone can view screenshot.

I noticed all these items where a link have been created are in the links section link section screenshot.

My questions are:

1)Since for a file or folder a link might have been created or not from the owner, how can I discover for each file or folder if a link does exist ?

2)In case a link does exist, how can I get it via API?

In case it does not exist I don't want to create one.

I hope my questions make sense.

 

I thank you in advance for your hard work.

 

5 Replies 5

Steve M.
Dropbox Staff

You can use /sharing/list_shared_links, passing the path to the file. If you only want links to that exact path (and not parent folders), use direct_only=true.

Aldo M.2
New member | Level 1

okay I realized only today all my links are expired.

I put together something like this but it is incomplete..

 


private List<SharedLinkMetadata> retrieveAllSharedLinks(DbxClientV2 client ) throws DbxException
{
    List<SharedLinkMetadata> result = new ArrayList<SharedLinkMetadata>();
    ListSharedLinksResult resultList = client.sharing().listSharedLinksBuilder().withPath(").withDirectOnly(true).start();
     
    while (true) {
        
        for (SharedLinkMetadata sharedLinkMetadata : resultList.getLinks()) {  
            result.add(sharedLinkMetadata);
        }

        if (!resultList.getHasMore()) {
            break;
        }
     
        //resultList = client.sharing().listSharedLinks().   I don't know what to put in this line here
    }
    return result;
}


It misses the pagination since I don't know how to get the others...
I looked the whole Internet but I couldn't get this snippet of code.

I bet it should be something similar to
 resultList = client.files().listFolderContinue(resultList.getCursor());

but it's for sharedlinks.

Will you give me further help?  I beg you...



Steve M.
Dropbox Staff

Untested, but I believe it's just this:

client.sharing().listSharedLinksBuilder()
.withPath(")
.withDirectOnly(true)
.withCursor(resultList.getCursor())
.start();

See the documentation: https://www.dropbox.com/developers/documentation/http/documentation#sharing-list_shared_links.

Steve M.
Dropbox Staff

Also, you may want to drop the .withPath(") in both calls if you're just trying to search for all links.

Aldo M.2
New member | Level 1

Hi,

I gave up with getting the links all at once and I fetch the shared links once per time.
I put back the .withPath(path) and I passed the path wanted without any cycle to get the others.

It's too difficult to figure out the pagination to get all the links at once without a template snippet in at least one of the languages among C, Python or Java or another.

Thanks for your time again.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Aldo M.2 New member | Level 1
  • User avatar
    Steve M. Dropbox Staff
What do Dropbox user levels mean?