Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
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 dedicated to this app. This script needs to read those files at regular interval (currently every 15 minutes). When I set up this app, I generated a token that I now provide to my python script every time I need to launch it. Things have been working fine up until now.
I have been warned of the API update, notably related to authentication, by an email in November 2020.
Now I'm tring to see if I need to change something to my app in order to adapt to this update, and if yes, to implement that change.
However it has been difficult to find out if I need to do something, and if yes, what.
If I understand properly what I read on this page (https://developers.dropbox.com/fr-fr/oauth-guide), as long as only me is using this app, I can use a token generated in the OAuth 2 Section of the Setting menu of my app, and set its expiration setting to 'No expiration'. However, in the help box, it is said that such tokens will be deprecated in the future, so if possible I'd like to anticipate that.
When I look at the table at the end of this page, in the "Summary" section, if I parse it properly, my app falls within the "A server-side application that requires background access." category, which means what I should "Use the OAuth code flow, with refresh tokens.".
The thing is, I'm not sure of how to do that. When I look at examples available here (https://www.dropbox.com/developers/reference/getting-started?_tk=guides_lp&_ad=tutorial5&_camp=get_s...), seems like it's just using the long-lived token method that I'm already using.
I found some examples script for the python SDK here (https://github.com/dropbox/dropbox-sdk-python/tree/main/example/oauth) but I'm not sure which one to follow.
From what I can see, I will always need to interact with the script every time I launch it, in order to copy the authorization code and provide it to the script, is that right?
Basically my question is: what is the script setup that I need to do, that will minimize the interaction with Dropbox required from me, while making sure that my app is still functional and compliant with Dropbox's future deprecation, for the time being?
@tszikszai You need to supply the refresh token to the dropbox.Dropbox constructor so it can use it to perform the refresh automatically when needed. Please refer to the example of how to construct that with a refresh token here.
I guess I am just trying to get to the next line of code of how to use this client to actually upload a file to Dropbox. Could you give me a code example?
@tszikszai Once you have a client constructed with a refresh token, you can use it to upload a file the same was as before, by calling files_upload.
Here's some simplified code from the example, combined with some of your uploading code, as an example:
import dropbox
APP_KEY = "APPKEYEHERE"
APP_SECRET = "APPSECRETHERE"
REFRESH_TOKEN = "REFRESHTOKENHERE"
dbx = dropbox.Dropbox(oauth2_refresh_token=REFRESH_TOKEN,
app_key=APP_KEY,
app_secret=APP_SECRET)
local_file_path = "/local/path/here"
dropbox_path = "/destination/path/here"
with open(local_file_path, 'rb') as f:
result = dbx.files_upload(f.read(), dropbox_path, mode=dropbox.files.WriteMode.overwrite)
print(result)
Thank you!!!! Exactly what I was looking for!!
Hi there!
If you need more help you can view your support options (expected response time for a 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!