We Want to Hear From You! What Do You Want to See on the Community? Tell us here!
Forum Discussion
dpellic996
2 years agoNew member | Level 2
help: long-live tokens for dropbox app
Hello everyone,
I know that there are other issues related to this but I did not find anything that really helped me.
I'm trying to upload images (.png) from my PC to dropbox via an application that I already created.
I'm doing this using a python script I wrote. The part that concerns the dropbox upload is the following:
def upload_to_dropbox(file_path, dropbox_token, dropbox_folder):
dbx = dropbox.Dropbox(dropbox_token)
with open(file_path, 'rb') as f:
filename = os.path.basename(file_path)
dropbox_path = dropbox_folder+filename
dropbox_path = dropbox_folder+filename
dbx.files_upload(f.read(), dropbox_path)
shared_link_metadata = dbx.sharing_create_shared_link(dropbox_path)
return shared_link_metadata.url
In doing this I'm using an access token that I generate in the Console App. This token begins with "sl" and I know that expires in few hours.
Could you please provide me support on how to get a long-live token, or how to refresh automatically the token I'm using?
Thank you in advance 🙂
D.
return shared_link_metadata.url
In doing this I'm using an access token that I generate in the Console App. This token begins with "sl" and I know that expires in few hours.
Could you please provide me support on how to get a long-live token, or how to refresh automatically the token I'm using?
Thank you in advance 🙂
D.
7 Replies
- amelialeo26 days agoNew member | Level 2
I had the same problem, and Long Path Tool fixed it quickly. You should try it too.
- Здравко2 years agoLegendary | Level 20
dpellic996 wrote:...
sorry for the confusion, i'm not very into these things and I find this very complicated!
...Hi dpellic996,
As Greg already noted, you can initiate and perform authorization (granting access to particular account data) either by hand (without redirect URI; copy-past access code by hand) or automated (automatic redirect from Dropbox site back to your application). An example, that uses redirect URL and that you can take a look on, can be seen here. 😉 I believe this will give you idea how the things could go.
Hope this helps.
- Greg-DB2 years ago
Dropbox Community Moderator
No, a redirect URI is not required to get a refresh token. Whether or not a redirect URI is used though, the manual authorization step does need to be handled by the user manually in order to authorize the app to access their account and receive a refresh token. This only needs to be done once per account though; the refresh token can then be stored and re-used programmatically without the user present.
- dpellic9962 years agoNew member | Level 2
So, if I got it right, using a redirect URI is the only way for generating a refresh token automatically (i.e. not manually by authorizing by myself)?
sorry for the confusion, i'm not very into these things and I find this very complicated!
D. - Greg-DB2 years ago
Dropbox Community Moderator
The redirect URI is the location where the user should be sent after they authorize the app to access their account. It should be a URI controlled by your app and defined by you as the developer of the app. That being the case, I can't tell you exactly what yours should be, but for example, if you're building a web app and your redirect URI for your development environment looks like http://localhost/auth, then it would typically look like https://example.com/auth in the deployed environment. For reference, it is optional; you can opt to not use a redirect URI, in which case you would omit that parameter and the user would need to manually copy/paste the authorization code. For instance, the Python SDK samples I linked to don't use a redirect URI.
- dpellic9962 years agoNew member | Level 2
Thank you but I have still a doubt on this..
I don't know any REDIRECT URI.. how can I get one? What's the criterion I could use to choose one? Actually is the only thing I still don't have. - Greg-DB2 years ago
Dropbox Community Moderator
Dropbox is no longer offering the option for creating new long-lived access tokens. Dropbox is now issuing short-lived access tokens (and optional refresh tokens) instead of long-lived access tokens. You can find more information on this migration here.
Apps can still get long-term access by requesting "offline" access though, in which case the app receives a "refresh token" that can be used to retrieve new short-lived access tokens as needed, without further manual user intervention. You can find more information in the OAuth Guide and authorization documentation. There's a basic outline of processing this flow in this blog post which may serve as a useful example.
The official Dropbox SDKs can handle this automatically for you. For the official Dropbox Python SDK, you can find examples of this flow at the following links:
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,035 PostsLatest Activity: 2 years ago
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 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!