Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

NavPanchhi's avatar
NavPanchhi
Explorer | Level 3
4 years ago

Simple file name retrieving using javascript

Hello,

I'm really new to working with the dropbox API and was completely lost on how to retrieve file names. My main goal is to just have a list of the files' names that are uploaded to Dropbox display on my website as simple text. I've tried using the chooser that was in the documentation but I can't seem to get the file names. I just get the popup window (and no alert). So far this is the only code I have. I'm genuinely lost on this. Any help would be great

<script type="text/javascript" src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs" data-app-key="************"></script>

<script>

options = {
success: function(files) {
console.log(files[0].name);
alert("Here's the file link: " + files[0].link);
},
cancel: function() {
linkType: "direct",
multiselect: false,
folderselect: false
sizeLimit: 1024,

};
Dropbox.choose(options);

</script>

8 Replies

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    4 years ago

    The Dropbox Chooser is a way to allow end-users to select specific files/folders and send them to the app. Based on your description, it sounds like that's not exactly what you're looking for. The Dropbox Embedder might be a better solution for you though. That lets you supply a (view-only) shared link, e.g., for a particular folder, and displays the contents of that folder on a web site.

     

    Alternatively, if you need a more custom integration, you would need to use the Dropbox API instead. That allows you to programmatically list files and folders. For example, to list the contents of any particular folder, you would use the /2/files/list_folder[/continue] endpoints to list the contents of a specific path, and the results would include the name of each item. By the way, those are links to the documentation for the HTTPS endpoints themselves, but we recommend using one of the official SDKs if possible. Those have corresponding native methods for the HTTPS endpoints. The Getting Started and File Access guides may also helpful if you decide to use this option.

  • NavPanchhi's avatar
    NavPanchhi
    Explorer | Level 3
    4 years ago

    Hello,

     

    I am currently using the ajaz call below to achieve what I need but am still facing issues.

     

    $.ajax({
    type: 'POST',
    url: 'https://api.dropboxapi.com/2/files/get_metadata',
    data: "{\"include_deleted\":false,\"include_has_explicit_shared_members\":false,\"include_media_info\":false,\"path\":\""}",
    contentType: "application/json",
    beforeSend: function(xhr) {
    xhr.setRequestHeader("Authorization", "Bearer ***")
    }, success: function(data){
    console.log(data);
    }
    })

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    4 years ago

    Please clarify what you mean when you say you are "still facing issues". For example, share any unexpected error or output.

  • NavPanchhi's avatar
    NavPanchhi
    Explorer | Level 3
    4 years ago

    Sorry about that!

    The issue that is appearing now is 

    Failed to load resource: the server responded with a status of 400 () https://api.dropboxapi.com/2/files/get_metadata

     

    The entire code I have is this:

    <script>

    $.ajax({
    type: 'POST',
    data: "{\"include_deleted\":false,\"include_has_explicit_shared_members\":false,\"include_media_info\":false,\"path\":\"}",
    contentType: "application/json",
    beforeSend: function(xhr) {
    xhr.setRequestHeader('Authorization', 'Bearer ***)
    }, success: function(data){
    console.log(data);
    //process the JSON data etc
    }
    })

    </script>
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    4 years ago

    What's in the response body for that response with the 400 status code? It should contain a more specific error message.

  • NavPanchhi's avatar
    NavPanchhi
    Explorer | Level 3
    4 years ago

    Here's more 

    Error in call to API function "files/get_metadata": Your app is not permitted to access this endpoint because it does not have the required scope 'files.metadata.read'. The owner of the app can enable the scope for the app using the Permissions tab on the App Console.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    4 years ago

    This latest message is what I was referring to. It indicates that the call failed because your app does not have the necessary scope for that endpoint. You can enable the scope on the app's page on the App Console as described. Note that you'd need to then get a new access token as that change does not retroactively affect existing access tokens.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!