cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Are you an educator? Well we want to hear from you, so check out some tools we think might help you out here!

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Share a file, then return the URL ONLY

Share a file, then return the URL ONLY

mnoah66
Explorer | Level 4

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!

 

1 Accepted Solution

Accepted Solutions

Re: Share a file, then return the URL ONLY

Greg-DB
Dropboxer

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)

View solution in original post

3 Replies 3

Re: Share a file, then return the URL ONLY

JohnnyNPC
Explorer | Level 3

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

Re: Share a file, then return the URL ONLY

Greg-DB
Dropboxer

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)

View solution in original post

Re: Share a file, then return the URL ONLY

mnoah66
Explorer | Level 4

That worked!  Thank you

Poll
We love to learn from the educators who use Dropbox. Whether you teach kids, teens, adults or a combination of all three, we want to know what apps and integrations you use with Dropbox to help with teaching. Which of the ones below is your favorite, or most used tool?
Who's talking

Top contributors to this post

  • User avatar
    mnoah66 Explorer | Level 4
  • User avatar
    Greg-DB Dropboxer
  • User avatar
    JohnnyNPC Explorer | Level 3
What do Dropbox user levels mean?
Need more support?