You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
oen124
4 years agoNew member | Level 2
How to get a refresh token
I have an app written in Python to upload files which I set up in the www.dropbox.com/developers/apps section. I generated an access token and chose the expiration to be "No Expiration". When I run it manually with "python app_name.py" it works. But when I setup a cron job (with the same python interpreter etc.) I receive the error:
raise BadInputException('OAuth2 access token or refresh token must be set')
dropbox.dropbox_client.BadInputException: OAuth2 access token or refresh token must be set
I tried to look for instructions about how to get this refresher token but didn't find anything. What's going on? How it works when I do it manually? Please assist.
If you're using a long-lived access token (e.g., as you described, by setting the "Access token expiration" setting in the App Console to "No Expiration" and then using the "Generate" button to generate an access token for your account and app), then you don't also need a refresh token. (Refresh tokens are for use with short-lived access tokens, not long-lived access tokens. Please note that long-lived access tokens are considered deprecated though. )
The particular error you're getting here is indicating that you did not pass a non-empty value for either the oauth2_access_token parameter (for a long-lived or short-lived access token) or oauth2_refresh_token (for a refresh token) when building your client. At least one of these parameters is needed to make API calls.
How are you passing your access token in and constructing that Dropbox object? It sounds like something about your environment isn't successfully retrieving your access token when running from the cron job.
- Greg-DBDropbox Staff
If you're using a long-lived access token (e.g., as you described, by setting the "Access token expiration" setting in the App Console to "No Expiration" and then using the "Generate" button to generate an access token for your account and app), then you don't also need a refresh token. (Refresh tokens are for use with short-lived access tokens, not long-lived access tokens. Please note that long-lived access tokens are considered deprecated though. )
The particular error you're getting here is indicating that you did not pass a non-empty value for either the oauth2_access_token parameter (for a long-lived or short-lived access token) or oauth2_refresh_token (for a refresh token) when building your client. At least one of these parameters is needed to make API calls.
How are you passing your access token in and constructing that Dropbox object? It sounds like something about your environment isn't successfully retrieving your access token when running from the cron job.
- oen124New member | Level 2
Thanks,
Yeah my problem was that I did not specify the line correctly in crontab, I had to source my profile file in order for the env vars to be seen by the cron job. Thanks a lot.
You said that long lived tokens are deprecated, does that mean it won't be available soon?
p.s - you have a bug here in the forums, each time I refresh the page it adds +1 to the views count of the message 🙂
- Greg-DBDropbox Staff
Long-lived access tokens are now considered deprecated, but we don't currently have a plan to disable existing long-lived access tokens. (If that changes, we will of course announce that ahead of time.) That being the case, you can continue using existing long-lived access token(s).
Note though that after the change you won't be able to create new long-lived access tokens.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,891 PostsLatest Activity: 3 hours agoIf 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!