Dropbox REST API

Hey Folks,
I’ve been spending days trying to get the Dropbox REST API to work. I got the Twitter sample code to work and I’ve been trying to modify that code to work with Dropbox.

I swapped out the Twitter REST URLs with the appropriate Dropbox REST URLs, but I run into a problem when I attempt to request token:
https://api.dropbox.com/1/oauth/request_token

Here is the error message I get when attempting the above request:
{“error”: “OAuthError in API v1+. Request mis-signed: Invalid or Missing Signature”}

Dropbox says that they require UTF-8 encoding and unicode normalization (NFC), but Twitter also says they require UTF-8 encoding and the sample code works fine with Twitter.

Just in case, I found a UTF-8 encoding library for Lua in the code exchange, but I’m not quite sure at what point in the request process the encoding should occur- do I encode the app key and app secret prior to doing anything else?

I have also read that it is recommended to use PLAINTEXT for Dropbox instead of HMAC-SHA1 as an oauth signature method (they say if you use https, it’s PLAINTEXT is fine). I tried to use PLAINTEXT, but for some reason I get an error message (from Dropbox) that I must use HTTPS if I want to use PLAINTEXT, but my code looks like it is using https. The Twitter code example uses http.request, but from my reading of the Corona API, it looks like that does not support HTTPS. It’s weird, though, because the Twitter example uses https URLs and they seem to work fine with http.request. Even so, I’m thinking I might do better using network.request, but I’m not entirely sure how to convert from http.request to network.request in the Twitter sample code. Here’s the code snippet for your convenience:

function rawPostRequest(url, rawdata)  
 local r,c,h  
 local response = {}  
 r,c,h = http.request  
 {  
 url = url,  
 method = "POST",  
 headers =   
 {  
 ["Content-Type"] = "application/x-www-form-urlencoded",   
 ["Content-Length"] = string.len(rawdata)  
 },  
 source = ltn12.source.string(rawdata),  
 sink = ltn12.sink.table(response)  
 }  
 return table.concat(response,"")  
end  

If anyone has had any luck getting the Dropbox REST API to work, I would so love to hear about it. Or any opinions on my ideas above. Thanks. [import]uid: 104085 topic_id: 29909 reply_id: 329909[/import]

Help! I think I’m getting close, but I’m having problems with the asynchronous response. It seems like the response comes in too late for me to do anything with it. Anyone have any ideas on how to get my app to wait for a response? I modified the oAuth.lua file that came with the Twitter sample code. Here’s the specific situation:

function rawPostRequest(url, rawdata)  
 local response = ""  
  
 local function networkListener( event )  
 if ( event.isError ) then  
 print("Network error!")  
 else  
 print ( "RESPONSE: " .. event.response )  
 response = event.response  
 end  
 end  
  
 headers = {}  
 headers["Content-Type"] = "application/x-www-form-urlencoded"  
 headers["Content-Length"] = string.len(rawdata)  
 body = rawdata  
 local params = {}  
 params.headers = headers  
 params.body = body  
 network.request( url, "POST", networkListener, params)   
  
 return response  
end  

I call this routine in the following way:

 local result = rawPostRequest(request\_token\_url, post\_data)  
 print("result of rawPostRequest: "..result)  

When this code runs (on the Corona Simulator in Windows), the variable result prints out as a blank in the terminal window and then shortly after, this appears in the terminal window:
RESPONSE: oauth_token_secret=sf7kklajqi9vo53&oauth_token=03darmolnayp8u4

The second thing that appears is what I would like “result” to equal. I suspect that “rawPostRequest” is returning a value to “result” and later, the actual event.response comes in.

I would love some opinions on this. I feel like I’m getting close to getting the Dropbox REST API to work and if I do, I’ll share… [import]uid: 104085 topic_id: 29909 reply_id: 119965[/import]

Help! I think I’m getting close, but I’m having problems with the asynchronous response. It seems like the response comes in too late for me to do anything with it. Anyone have any ideas on how to get my app to wait for a response? I modified the oAuth.lua file that came with the Twitter sample code. Here’s the specific situation:

function rawPostRequest(url, rawdata)  
 local response = ""  
  
 local function networkListener( event )  
 if ( event.isError ) then  
 print("Network error!")  
 else  
 print ( "RESPONSE: " .. event.response )  
 response = event.response  
 end  
 end  
  
 headers = {}  
 headers["Content-Type"] = "application/x-www-form-urlencoded"  
 headers["Content-Length"] = string.len(rawdata)  
 body = rawdata  
 local params = {}  
 params.headers = headers  
 params.body = body  
 network.request( url, "POST", networkListener, params)   
  
 return response  
end  

I call this routine in the following way:

 local result = rawPostRequest(request\_token\_url, post\_data)  
 print("result of rawPostRequest: "..result)  

When this code runs (on the Corona Simulator in Windows), the variable result prints out as a blank in the terminal window and then shortly after, this appears in the terminal window:
RESPONSE: oauth_token_secret=sf7kklajqi9vo53&oauth_token=03darmolnayp8u4

The second thing that appears is what I would like “result” to equal. I suspect that “rawPostRequest” is returning a value to “result” and later, the actual event.response comes in.

I would love some opinions on this. I feel like I’m getting close to getting the Dropbox REST API to work and if I do, I’ll share… [import]uid: 104085 topic_id: 29909 reply_id: 119965[/import]