Android Question Curl Command using httpjob

Brad Henderson

Member
Licensed User
Can anyone help me execute this curl command using httpjob.

The Dropbox API documentation refers to this curl command:

curl https://api.dropbox.com/oauth2/token \
-d grant_type=refresh_token \
-d refresh_token=<REFRESH_TOKEN> \
-d client_id=<APP_KEY> \
-d client_secret=<APP_SECRET>

I have found a few httpjob examples in the forum, but my difficulty is how to supply the necessary parameters in the correct order. I have tried this:

B4X: Copy
Dim data As Map
    data.Initialize
    data.Put("grant_type", "refresh_token")
    data.Put("refresh_token", "<REFRESH TOKEN>")
    data.Put("client_id", "<APP_KEY>")
    data.Put("client_secret", "<APP_SECRET>")
    
    Dim j As HttpJob
    j.Initialize("", Me)
    j.PostString("https://api.dropbox.com/oauth2/token",data.As(JSON).ToString)
    j.GetRequest.SetContentType("application/json")
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
    Else
        Log(j.ErrorMessage)
    End If
    
    
    j.Release

This keeps resulting in this error:
{"error": "invalid_request", "error_description": "The request parameters do not match any of the supported authorization flows. Please refer to the API documentation for the correct parameters."}

I have tried the above code by including the "-d" before the first element of the data Map. Same result.

Your help is always appreciated.
 
1. Google search to find curl arguments: https://curl.se/docs/manpage.html#-d

2. Something like:
Code: Copy
    Dim j As HttpJob
    j.Initialize("", Me)
    Dim sb As StringBuilder
    sb.Initialize
    For Each Key As String In data.Keys
      Dim value As String = data.Get(Key)
       if sb.Length > 0 Then sb.Append("&")
      sb.Append(key).Append("=").Append(value)
    Next
    j.PostString("https://api.dropbox.com/oauth2/token", sb.ToString)
    j.GetRequest.SetContentType("application/x-www-form-urlencoded")
 
Upvote 0
Back
Top