Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
Hi, I'm trying to upload files from my website to dropbox and it was working, but i received an error message saying the Access Token Expired. I research a little bit, and read that now dropbox uses "refresh token". I'm trying to find an example or tutorial in order to change the code im using to make it work with refresh token, but I can't find anything. My question is: What do I need to change in this code to make it work with NON EXPIRE TOKEN.
Thanks.
<?php
Hi @Fenoma,
As a example you can take a look here. It's not a PHP code, but a command line curl execution. I believe you haven't problem to convert it. The most important is HOW it's gonna work (as idea).
The code you posted as example should not be changed a lot (it can left almost the same). You have not to assume 'ACCESS TOKEN' has a fixed value anymore (as seems you are doing). This token should be represented as rather variable and definitely not as a literal!!! Good idea is to change your code in a way, every place (no limited to your example) where token is used, the literal to be replaced with a function (you can name it to something like 'getToken' for instance). In this function implementation you can check whether available access token is going to expire and if so, refresh it (as denoted in the post linked to). You can keep refresh token, last received access token (as a cache), and calculated time (moment) of current access token expiration (used for check, in followup calls, whether the access token expires). 😉 That's it.
Hope this helps.
Hi @Fenoma,
As a example you can take a look here. It's not a PHP code, but a command line curl execution. I believe you haven't problem to convert it. The most important is HOW it's gonna work (as idea).
The code you posted as example should not be changed a lot (it can left almost the same). You have not to assume 'ACCESS TOKEN' has a fixed value anymore (as seems you are doing). This token should be represented as rather variable and definitely not as a literal!!! Good idea is to change your code in a way, every place (no limited to your example) where token is used, the literal to be replaced with a function (you can name it to something like 'getToken' for instance). In this function implementation you can check whether available access token is going to expire and if so, refresh it (as denoted in the post linked to). You can keep refresh token, last received access token (as a cache), and calculated time (moment) of current access token expiration (used for check, in followup calls, whether the access token expires). 😉 That's it.
Hope this helps.
@Fenoma Здравко is correct. For more information, refer to the following resources:
Hi Здравко, thank you so much for your reply. I think i'm still committing some mistakes. What I did was this:
1.- went to the link with all the data that the example says:
https://www.dropbox.com/oauth2/authorize?token_access_type=offline&response_type=code&client_id=<App key>
Then I got the access code on the browser and I copy it to the next step:
2.- I created a function in order to get the token:
Hi Здравко, thank you so much for your reply.
I follow all the steps and now it is working!!
i am using your code but i am facing this error
Notice: Array to string conversion in C:\xampp\htdocs\wordpress_forum\wp-content\themes\twentytwentyone-child\functions.php on line 115
Error in call to API function "files/upload": The given OAuth 2 access token is malformed.
@firoj_ali A "The given OAuth 2 access token is malformed" error indicates that the access token you're supplying in the call is not in a valid access token format. Make sure you supply the entire access token exactly as you received it from Dropbox, without any modification or truncation, for instance.
The following resources can be helpful for understanding and implementing the OAuth functionality on Dropbox:
If the API isn't working as expected, feel free to supply the steps and code to reproduce the issue. Don't share your actual access token, refresh token, or app secret though.
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!