iOS Question Help getting Dropbox Refresh token

Turbo3

Active Member
Licensed User
Longtime User
I would like to update my application's Dropbox support from using the short lived (4 hour) access toke to using the refresh token to allow long term access.

I have located a Dropbox example that works but uses a curl command to get the refresh token which I am trying to move to B4i

The following curl command works to get a "Refresh Token" when entered into a Windows Terminal once you have the Authorization code.

(In this example I have replace the valid "code" and client_id:secret with placeholders. Where Dropbox app key = aaaaa... and secret= sssss...)
curl https://api.dropbox.com/oauth2/token -d code=1234567890123456789012345678901234567890123 -d grant_type=authorization_code -u aaaaaaaaaaaaaaa:sssssssssssssss
Now I just need to convert that to code into something I can put into my B4i app.

Using the following website I converted the curl command to HTTP.
POST /oauth2/token HTTP/1.1
Host: api.dropbox.com
User-Agent: curl/8.2.1
Accept: */*
Authorization: Basic YWFhYWFhYWFhYWFhYWFhOnNzc3Nzc3Nzc3Nzc3Nzcw==
Content-Type: application/x-www-form-urlencoded
Content-Length: 78

code=1234567890123456789012345678901234567890123&grant_type=authorization_code
I then then tried to convert that to the following B4i code. But when executed in a not so helpful "request completed with error" from Dropbox.

Dim auth_code as string = "1234567890123456789012345678901234567890123"

Dim job As HttpJob
job.Initialize("get_refreshtoken",Me)

job.PostString("https://api.dropbox.com/oauth2/token","code="&auth_code&"&grant_type=authorization_code")

job.GetRequest.SetHeader("Authorization", "Basic YWFhYWFhYWFhYWFhYWFhOnNzc3Nzc3Nzc3Nzc3Nzcw==")
job.GetRequest.SetHeader("Content-Type", "application/json")
job.GetRequest.SetContentType("application/json")
job.GetRequest.SetContentEncoding("text/plain")
Could someone point out what I am doing wrong in this code? Thanks.
 
Last edited:

Turbo3

Active Member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

Why have you set the content type to json?
B4X:
job.GetRequest.SetContentType("application/x-www-form-urlencoded")
Sorry about the format.

Long time since I posted and I forgot and then missing where the code tag was even though it is the first thing listed. Getting old.

Removed the two json lines and all is working now.

Those two lines came from the DroboxV2 code I was using as a template for the POST. So a dumb error on my part.
 
Upvote 0
Top