0

I have added some files into my folder in Dropbox account. Beside of each document I have put a download button to show the files in Dropbox folder.

I have tried with sharelink with settings in Dropbox API, but it works only for one time. If i click it on second time it says sharelink already exists.

Is there any other way to preview the files from Dropbox folder to our page?

Below is the code for sharelink:

  $path='/test.txt';
   $ch = curl_init();
  $url1="https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings";
     $post = array(
             "path"=> "/".$path,
"settings"=> array(
    "requested_visibility"=> "public"
                  )

                 );
     $link = json_encode($post); 

     curl_setopt($ch,CURLOPT_URL,$url1);
     curl_setopt($ch,CURLOPT_POST, 1); 
     curl_setopt($ch,CURLOPT_POSTFIELDS,$link);
     curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

     $headers = array();
     $headers[] = 'Accept: application/json';
     $headers[] = 'Content-Type: application/json';
     $headers[] = "Authorization: Bearer ".$TOKEN;

     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);     
     $response1 = curl_exec($ch); 
     $sharelink  = json_decode($response1,true);
Greg
  • 16,359
  • 2
  • 34
  • 44
Reshma
  • 189
  • 2
  • 5
  • 18

1 Answers1

0

The /2/sharing/create_shared_link_with_settings endpoint is expected to return shared_link_already_exists if a link already exists. You can use /2/sharing/list_shared_links to retrieve existing links.

Alternatively though, you can use /2/files/get_temporary_link to get a temporary direct link to the file.

Or, for supported file types, you can use /2/files/get_preview to get a preview of the file data.

Greg
  • 16,359
  • 2
  • 34
  • 44