Dropbox, oauth and httputils2

juanM1

Member
Licensed User
Longtime User
Hi:
Sorry for my bad english ( google translate)

I was using dropbox with httputils, and now I update to httputils2.

Modify the following sub in httputils2service

B4X:
  Public Sub SubmitJob(job As HttpJob) As Int
   taskCounter = taskCounter + 1
   TaskIdToJob.Put(taskCounter, job)
   If job.Username <> "" AND job.Password <> "" Then
      hc.ExecuteCredentials(job.GetRequest, taskCounter, job.Username, job.Password)
   Else
      hc.Execute(job.GetRequest, taskCounter)            
[B]      OAuth.SetTokenWithSecret(Main.tokenKey, Main.tokenSecret)      
      OAuth.Sign(job.GetRequest)[/B]
   End If
   Return taskCounter
End Sub

Handle directory etc. OK
B4X:
  Dim job1 As HttpJob
  job1.Initialize("Job1" ,Me)
  job1.Download(metadataLink & p & "?")
  etc.....

Download a file from dropbox to tablet OK
B4X:
   Dim job2 As HttpJob            
   job2.Initialize("Job2" ,Me)
   job2.Download(downloadFileLink & "/file.db" & "?")
  etc...........

Upload a file from tablet to dropbox ERROR
B4X:
  Dim jEnviar As HttpJob   
  jEnviar.Initialize("jEnviar", Me)   
  jEnviar.PostFile( uploadLink, File.DirRootExternal,"frame0.png")

error in sub SubmitJob
B4X:
Public Sub SubmitJob(job As HttpJob) As Int
   taskCounter = taskCounter + 1
   TaskIdToJob.Put(taskCounter, job)
   If job.Username <> "" AND job.Password <> "" Then
      hc.ExecuteCredentials(job.GetRequest, taskCounter, job.Username, job.Password)
   Else
      hc.Execute(job.GetRequest, taskCounter)            
      OAuth.SetTokenWithSecret(Main.tokenKey, Main.tokenSecret)      
Error ---->   OAuth.Sign(job.GetRequest)
   End If
   Return taskCounter
End Sub
log
B4X:
Return req
java.lang.IllegalArgumentException: Invalid % sequence at 157: 
   at libcore.net.UriCodec.decode(UriCodec.java:169)
   at java.net.URLDecoder.decode(URLDecoder.java:67)
   at oauth.signpost.OAuth.percentDecode(OAuth.java:91)
   at oauth.signpost.OAuth.decodeForm(OAuth.java:146)
   at oauth.signpost.OAuth.decodeForm(OAuth.java:166)
   at oauth.signpost.AbstractOAuthConsumer.collectBodyParameters(AbstractOAuthConsumer.java:237)
   at oauth.signpost.AbstractOAuthConsumer.sign(AbstractOAuthConsumer.java:99)
   at oauth.signpost.AbstractOAuthConsumer.sign(AbstractOAuthConsumer.java:120)
   at anywheresoftware.b4a.objects.OAuth.Sign(OAuth.java:40)
   at Gebial.Probes.MiTabHost.httputils2service._submitjob(httputils2service.java:330)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
   at anywheresoftware.b4a.keywords.Common$4.run(Common.java:885)
   at android.os.Handler.handleCallback(Handler.java:725)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:5041)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
   at dalvik.system.NativeStart.main(Native Method)

   at anywheresoftware.b4a.keywords.Common$4.run(Common.java:888)
   at android.os.Handler.handleCallback(Handler.java:725)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:5041)
   at java.lang.reflect.Method.invokeNative(Native Method)

Thanks for you help

Juan Manuel
 

juanM1

Member
Licensed User
Longtime User
Hi Erel :

no difference between
B4X:
    hc.Execute(job.GetRequest, taskCounter)
    OAuth.SetTokenWithSecret(Main.tokenKey, Main.tokenSecret)
    OAuth.Sign(job.GetRequest)
and
B4X:
    OAuth.SetTokenWithSecret(Main.tokenKey, Main.tokenSecret)
    OAuth.Sign(job.GetRequest)
    hc.Execute(job.GetRequest, taskCounter)

You should sign the request before it is sent.

I appreciate you to tell me as I have not found anything in the forum

In the original code there was a sub named PrepareFileToUpload.

thanks I'll try
 
Last edited:
Upvote 0
Top