cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

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

New member | Level 1
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
Highlighted

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

Dropboxer
Dropboxer

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.

Highlighted

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

New member | Level 1
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...



Highlighted

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

Dropboxer
Dropboxer

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.

Highlighted

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

Dropboxer
Dropboxer

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

Highlighted

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

New member | Level 1
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.

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?