Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
FrancoisNOYEZ
5 years agoExplorer | Level 4
How to migrate to new Auth workflow with python SDK while minimizing need for single user input?
Hello Dropbox team,
I have set up a small app as a python script which runs continuously on my server, and which needs to read some files that I store on my Dropbox storage space, in the folder...
- 5 years ago
FrancoisNOYEZ Здравко is correct, under the new system you do not need to interact with your script every time it runs. You can supply it the refresh token like you previously supplied it a long-lived access token and it will automatically run without manual user interaction, as before.
You do need to process the app authorization flow one time to get a refresh token though. You can refer to this example to see how to process the app authorization flow to get a refresh token, at which point you can then set up a client using it, as shown at the end of the example.
tszikszai
3 years agoExplorer | Level 3
I have been struggling with getting a refresh token and I was able to run your example successfully so that is great thank you!! But what I am still struggling with are two things: 1) How do I get the refresh token out of this and 2) how do I use it in my python code to actually log into dropbox and automatically use a file. For example with a regular token I use the below code, but the problem with the regular token is that it keeps expiring. So what do I replace this code with???:
dbx = dropbox.Dropbox(access_token)
with open(local_file_path, 'rb') as f:
dbx.files_upload(f.read(), dropbox_path, mode=dropbox.files.WriteMode.overwrite)
Здравко
3 years agoLegendary | Level 20
Hi tszikszai,
You can take a look here for a working example. It targets different task, but you can get the object in dbx variable using getClient method instead of initializing by your own. In such a way everything, regarding OAuth flow, is done and you can use the result. 😉 Of course you can change whatever needed. So, your code would look like:
from <whatever you named the file> import ApplicationConfig
conf = ApplicationConfig()
dbx = conf.getClient()
with open(local_file_path, 'rb') as f:
dbx.files_upload(f.read(), dropbox_path,
mode=dropbox.files.WriteMode.overwrite)... or something similar. Isn't simpler? 😀 Just a note: While you can call getClient multiple times, conf object should be single one on global (or other) place/scope visible whenever need to be get a client. It should alive to the end of Dropbox API usage (usually end of the script).
Hope this helps.
About 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!