You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

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

Proper way to authorize python script?

hey guys,

 

been exploring the dropbox API and I'm loving it! so I have an application running some python code that connects to my dropbox, downloads some files, then installs them in various places on my computer. sadly, I can't use the dropbox python library with this setup... so I'm at a loss on how to make an HTTP request to authorize the script to do what it needs to do. during testing, I have been using the Acess token that's generated from the API explorer but this obviously expires...

 

so what's the proper way to get access tokens for a script that runs by itself, it doesn't really have any user interaction.

  • jmccolgan93's avatar
    jmccolgan93
    Explorer | Level 3

    so ive made an app using the App Console and made an access token there that doesn't expire (yeah I know that's not recommended...), I'm able to make API calls but none of them are working... I'm using the API Explorer to test and I keep getting an error that the paths not found.

    import requests
    import json
    
    url = "https://api.dropboxapi.com/2/files/list_folder"
    
    headers = {
        "Authorization": "Bearer IMHIDINGMYACCESSTOKEN",
        "Content-Type": "application/json"
    }
    
    data = {
        "path": "/MIG/VW Scripting/_plugins"
    }
    
    r = requests.post(url, headers=headers, data=json.dumps(data))
    {
      "error_summary": "path/not_found/..",
      "error": {
        ".tag": "path",
        "path": {
          ".tag": "not_found"
        }
      }
    }

     

    • Greg-DB's avatar
      Greg-DB
      Icon for Dropbox Staff rankDropbox Staff

      If you can't use an SDK/library, you'll need to implement the requests yourself, like you mentioned. And to allow a user, such as yourself, to connect an app to their account without expiration, you'd need to implement the OAuth app authorization flow, and specifically request "offline" access. I recommend reading the OAuth Guide and authorization documentation for information on how this works. With the new short-lived access token and refresh token functionality, an app can get long-lived access by requesting "offline" access, so that it receives a refresh token that it can use to automatically retrieve new short-lived access tokens whenever needed, without further manual user interaction.

       

      For reference, long-lived access tokens, like you mentioned you are currently using, are now considered deprecated, but we don't currently have a plan to disable existing long-lived access tokens. (If that changes, we will of course announce that ahead of time.) That being the case, you can continue using existing long-lived access token(s). Note though that after the change you won't be able to create new long-lived access tokens.

       

      As for the "path/not_found" error you're getting, it sounds like the issue may be that you registered your app for "app folder" access, but are attempting to access content outside of the app folder. Apps with "app folder" access can only access the contents of the special app folder that gets created for them when the app is connected to the account. If you need to access other contents of the account, such as a shared folder, for instance, you'll need to register an app with "full Dropbox" access instead. You can find more information on the different app permissions here.

       

      You can also supply an empty string "" as the "path" parameter value when calling /2/files/list_folder to list the contents of the root folder, which will be the app folder for an app with app folder access.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,879 PostsLatest Activity: 3 hours ago
326 Following

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 or Facebook.

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!