cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close

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: 
Highlighted

Access Token Changes Every time I use it

New member | Level 1
New member | Level 1

Hi,

I'm working on a DIY motion detection project with a raspberry pi and I was able to save image files to my dropbox by using the generated access token (which is ridiculously long btw). My issue is that the token changes after every use. Is there a way to get a permanent access code?

 

Thanks,

Dan 

6 Replies 6
Highlighted

Re: Access Token Changes Every time I use it

Dropboxer
Dropboxer

What do you mean when you say the access token changes after every use? Do you mean you're clicking the Generate button each time you need an access token? 

Access tokens don't expire by themselves (though they can be manually revoked), so once you generate one for your account, you can store and re-use it programmatically in the future, without generating a new one.

Highlighted

Re: Access Token Changes Every time I use it

New member | Level 1
New member | Level 1
Originally I was using this code to upload to my dropbox folder...
---------------
from dropbox.client import DropboxOAuth2FlowNoRedirect
from dropbox.client import DropboxClient
 
if conf["use_dropbox"]:
# connect to dropbox and start the session authorization process
flow = DropboxOAuth2FlowNoRedirect(conf["dropbox_key"], conf["dropbox_secret"])
print "[INFO] Authorize this application: {}".format(flow.start())
authCode = raw_input("Enter auth code here: ").strip()
 
# finish the authorization and grab the Dropbox client
(accessToken, userID) = flow.finish(authCode)
client = DropboxClient(accessToken)
print "[SUCCESS] dropbox account linked"
---------------
 
With this, every time I ran the code, It would ask me to enter the dropbox link into my URL, enter my dropbox email and password, and then it would give me the access token. 
 
I tried replacing the lines asking for the token with the token hard coded in...
 
print "[INFO] Authorize this application: {}".format(flow.start())
authCode = raw_input("Enter auth code here: ").strip()
with
authCode = ("ACCESS_TOKEN_HERE")
 
This worked once but then fails when I try to run the program again and I need to get another token.
Highlighted

Re: Access Token Changes Every time I use it

Dropboxer
Dropboxer

Thanks for clarifying. The code you're referring to is an authorization code, not an access token. Authorization codes are temporary, and can only be used once. So, instead of trying to re-use an authorization code or authorizing the app each time, you should store and re-use the resulting access token, passing it directly to the DropboxClient constructor.

Highlighted

Re: Access Token Changes Every time I use it

New member | Level 1
New member | Level 1

Thanks! 

It worked!

Highlighted

Re: Access Token Changes Every time I use it

New member | Level 1
New member | Level 1

Are you really sure that access token will not expire at all. How do I can see the old access tokens ?

Or Can I request token via client api along with the old one?

Highlighted

Re: Access Token Changes Every time I use it

Dropboxer
Dropboxer

c. chunta, correct, access tokens don't expire.

You need to store the access token yourself to keep using it. There's no way to ask Dropbox for previous access tokens, but you can always get a new access token by taking a user through the OAuth flow.

Polls
Do you know how to organize your files and folders?
We have created a guide on folder best practice, so you can get organized now check it out here.

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?