cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We love to hear how every person gets the most from Dropbox, and it seems everyone has a slightly different use for it - tell us yours here!

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Proper way to authorize python script?

Proper way to authorize python script?

jmccolgan93
Explorer | Level 3

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.

2 Replies 2

Re: Proper way to authorize python script?

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"
    }
  }
}

 

Re: Proper way to authorize python script?

Greg-DB
Dropboxer

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.

Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropboxer
  • User avatar
    jmccolgan93 Explorer | Level 3
What do Dropbox user levels mean?
Need more support?