Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
pkd
3 years agoExplorer | Level 3
How do I upload file using Python
I've checked here and over at StackOverflow but couldn't find a solution. Nothing works.
It says that I need refresh token (I have no clue where to get it) and an app key.
import pathlib...
pkd
3 years agoExplorer | Level 3
Good God, this seems so overly complicated. It's literally 10 lines of code for S3.
I think I'll use some other service instead of Dropbox.
Greg-DB
Dropbox Community Moderator
3 years agopkd I see Здравко helpfully shared a more fully-featured script, but much like what you originally shared, it is possible to upload to Dropbox using the API automatically once you process the authorization flow (which only needs to be done once) with minimal code.
The minimal usage to upload/overwrite a file over extended periods of time would look like this: (using credentials acquired using PKCE, like in Здравко's example)
import dropbox
dbx = dropbox.Dropbox(oauth2_refresh_token="REFRESHTOKENHERE", app_key="APPKEYHERE")
print(dbx.files_upload(b"some data here", "/upload_path/file.ext", mode=dropbox.files.WriteMode("overwrite")))
- pkd3 years agoExplorer | Level 3
I chose "Allow public clients (Implicit Grant & PKCE)" in Settings but still there's no refresh token. Is it even possible to set this whole thing up using web interface at Dropbox?
- Здравко3 years agoLegendary | Level 20
pkd, Did you get some error or something? 🧐 The refresh token gets in the configuration file (on OAuth flow success) and stay there, where it's read on command start. The file gets updated whenever needed to minimize needed refreshes. Take a look in the configuration file (named 'cert.json', in my script, residing in 'dropbox_file' configuration folder) to take refresh token and use somewhere else if you want to (or copy the entire file). The configuration folder can be found in the standard place for configuration data according your platform. As Greg mentioned the refresh token, once received, can be used in very simplistic scripts without further user authentication. Don't forget to set the needed permissions/scopes, matching to your needs or add the needed as soon as you get error that they're missing (and receive the refresh token anew, such a change is NOT retroactive).
- Greg-DB3 years ago
Dropbox Community Moderator
pkd Yes, it is possible to use this flow on web. The setting you mention enables flows for client-side applications, but either way you can still request "offline" access to get long-term access via a refresh token, regardless of what kind of platform you're working from.
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!