Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
I am using Python to share an image. Then, I want to be able to only print to the console the short url. How do I accomplish this?
With this:
print(client.share(path))
I get:
{'visibility': 'PUBLIC', 'expires': 'Tue, 01 Jan 2030 00:00:00 +0000', 'url': 'https://....'}
What I want:
https://....
Any help is greatly appreciated!
The share method you're using returns a dict, so you can access the fields like:
print(client.share(path)['url'])
That uses API v1 though, which is deprecated. You should switch to using API v2. Using API v2, creating a shared linked is accomplished using the sharing_create_shared_link_with_settings method, which returns a SharedLinkMetadata object. Using it would look like this (also including the construction of the client itself):
dbx = dropbox.Dropbox(ACCESS_TOKEN)
print(dbx.sharing_create_shared_link_with_settings(path).url)
I'm not too familiar with de-serializing JSON in python, but you are getting a JSON object if you convert that JSON into an object you can just retrieve the URL member of that object
The share method you're using returns a dict, so you can access the fields like:
print(client.share(path)['url'])
That uses API v1 though, which is deprecated. You should switch to using API v2. Using API v2, creating a shared linked is accomplished using the sharing_create_shared_link_with_settings method, which returns a SharedLinkMetadata object. Using it would look like this (also including the construction of the client itself):
dbx = dropbox.Dropbox(ACCESS_TOKEN)
print(dbx.sharing_create_shared_link_with_settings(path).url)
That worked! Thank you
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!