title: download a users file from dropbox - javascript
body: <p>I want to download a file that the user selects from dropbox - so far I have used javascript and the API to list the users files.</p>
  
  <p>When the user selects a file, the only information I have is the path (not the full path, e.g '/getting started.pdf')</p>
  
  <p>The user has already authorized my app to access their file data so I have an access token, but I cant figure out the direct url I need to download the file.</p>
  
  <p>I've been trying to use these urls:</p>
  
  <pre><code>https://dl.dropboxusercontent.com/1/view/XXXXXXXXXXXXXXXXX/getting started.pdf
  https://dl.dropboxusercontent.com/s/XXXXXXXXXXXXXXXXX/getting started.pdf
  </code></pre>
  
  <p>but I always get a 401 not authorized, even when setting the 'Authorization' header. how can I download the file? And, what number is supposed to replace XXXXXXXXXXXXX ?? I've tried both my app id and app secret but nothing seems to work.</p>
  
  <p>the basics of my code are:</p>
  
  <pre><code>var access_token = 'XXXXXXXXXXXXXXXXXXXXXXXX';
  var api_secret = 'XXXXXXXXXXXXX';
  var api_key = 'XXXXXXXXXXXXXXX';
  
  $('body').on('click', '.dropbox-doc', function(event){
      var path = $(this).data().path;
  
      $.ajax({
          url: 'https://dl.dropboxusercontent.com/1/view/'+api_key+path+'?dl=1',
          dataType:'json',
          headers: {
              'Authorization':'Bearer '+access_token,
          },
          success: function(data){
              console.log('success')
              console.log(data)
          },
          error: function(data){
              console.log(data)
          }
      });
  });
  </code></pre>
  
  <p>I also tried opening the url in a new window instead of ajaxing and I get the same 401 error</p>