cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to know what we learned at IBC? Check out our learnings on media, remote working and more right 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
Go to solution

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

Greg-DB
Dropbox Staff
Go to solution

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

JohnnyNPC
Explorer | Level 3
Go to solution

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

Greg-DB
Dropbox Staff
Go to solution

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)

mnoah66
Explorer | Level 4
Go to solution

That worked!  Thank you

Need more support?
Who's talking

Top contributors to this post

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