Cannot create a shared link with Dropbox SDK

310 Views Asked by At

I'm having an issue logging the sharingCreateSharedLinkWithSettings method response. I've tried using short and long lived tokens and I get 409/400/401 error codes. I'm also not too sure what the path should be. If the app folder is called tron and I have a file named cabin.mp3 in that folder should the path string be /tron/cabin.mp3, cabin.mp3 or /cabin.mp3. I'm also not sure if I'm just having an authentication issue even though I'm passing the accessToken.

I don't have issues displaying the file names with the filesListFolder method so not sure what I'm missing.


import './App.css';
import { Dropbox } from 'dropbox';


var dbx = new Dropbox({ accessToken: ACCESSTOKEN });


dbx.filesListFolder({path: ''})
  .then(function(response) {
    console.log(response);
    displayFiles(response.result.entries);
  })
  .catch(function(error) {
    console.log(error);
  });




dbx.sharingCreateSharedLinkWithSettings({path:'/tron/cabin.mp3'})
  .then(function(response){
    console.log('share:' + response)
    displaySharedLinks(response);
  })
  .catch(function(error){
    console.log(error);
  })

function displayFiles(files) {
      var filesList = document.getElementById('files');
      var li;
      for (var i = 0; i < files.length; i++) {
        li = document.createElement('li');
        li.appendChild(document.createTextNode(files[i].name));
        filesList.appendChild(li);
      }
}


function App() {
  return (
    <div className="App">
      <header className="App-header">
        <div id="files"></div>
 
      </header>
    </div>
  );
}




export default App;
1

There are 1 best solutions below

0
On

The status codes, such as the 400, 401, and 409 codes you're getting, just indicate the type of the response error. You can get more specific error information from the nested API error object like this:

  .catch(function(error){
    console.log(error.error);
  })

For example, with a 409 error, you may get an API error like path/not_found, indicating that there's nothing at that path in the connected account.

As for the path you should be using, that depends on the state of the account, and what kind of access your app has. In general though, you can use the path_lower returned for an item by other calls, such as from filesListFolder/filesListFolderContinue or filesGetMetadata.

Note that apps using the "app folder" type are rooted in the special app folder created for the app. API calls for apps using that type are automatically performed relative to the app folder itself, so you shouldn't also provide the path to the app folder itself when making API calls for that kind of app, such as to list the contents of a folder.

That means that if you want to access a "tron" folder inside the app's app folder, instead of "/Apps/AppName/tron" you would just call with "/tron". Likewise, to access a file at "/Apps/AppName/tron/cabin.mp3" you would just supply "/tron/cabin.mp3". Or, if you meant "/tron" is the path of the special app folder, and the file is directly inside that, you would supply just "/cabin.mp3".

Apps with the "full Dropbox" type can access anything in the account and so should supply the full path.

You can find more information in the File Access Guide.