Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Dropbox Rest Api Sample Code In Code Exchange
Started by michael714 Apr 01 2013 06:29 PM

34 replies to this topic
dropbox rest oauth sample network
[TOPIC CONTROLS]
Page 2 of 2 1 2
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#26

xnailbender

[GLOBAL: userInfoPane.html]
xnailbender
  • Contributor

  • 362 posts
  • Corona SDK

@hmob,

 

The code in exchange worked for me with the modifications I made above.  I don't know of an updated version.

 

You'll probably be making the Dropbox URL  dynamically, so make sure to take out any spaces in the URL or it wont' work.  If your app will allow users to create and label their files to be uploaded,/downloaded,  sub out the spaces in the label strings.

 

It's cool how Dropbox will dynamically create  folders in the parent if they don't exist.

 

GL

 

Nail



[TOPIC: post.html]
#27

michael714

[GLOBAL: userInfoPane.html]
michael714
  • Contributor

  • 170 posts
  • Corona SDK

Hey Folks,

It's been a while since I looked at the Dropbox code and I like what Wyldcard did.  However, the module implementation seemed like it was incomplete.  So, I made a few changes and I am sharing them here with you: https://www.dropbox.com/sh/evttsokenvqp7lv/AADr47rIPBq6-HR3Akm7YOyra

 

I've included a DropBoxModule file and a download.lua file which demonstrates how you use the DropboxModule.lua file.   Hope this helps!



[TOPIC: post.html]
#28

michael714

[GLOBAL: userInfoPane.html]
michael714
  • Contributor

  • 170 posts
  • Corona SDK

I also posted this version in the new Code Exchange.



[TOPIC: post.html]
#29

silvermorph

[GLOBAL: userInfoPane.html]
silvermorph
  • Observer

  • 2 posts
  • Corona SDK

Thanks VERY much for putting this together. I'm using this as a base to build out other parts of the api, but I'm running into trouble with the fileops/copy command. It seems to be ignoring the values in the params table, whether I pass them in at the top level of the table, as a set of headers, or as a body. Do you happen to know the correct way to pass the params table to that command?

Here's what I've got:

 

function M.copyWithCopyRef( path, fileName, listener, copy_ref )
local url = "https://api.dropbox.com/1/fileops/copy" .. "?" .. authString
local params = {}
params["root"] = "sandbox"
params["from_copy_ref"] = copy_ref    --params["from_path"] = "/myFile.txt" -- same error
params["to_path"] = path..fileName
network.request( url, "POST", listener, params )
end

 

API Reference: https://www.dropbox.com/developers/core/docs#fileops-copy

error from dropbox:
{"error": "Must send either a from_path or a from_copy_ref"}

Also, when I'm done converting more of the API over I'll be happy to send you my module to include in the code exchange if you'd like.

 

Thanks again!



[TOPIC: post.html]
#30

michael714

[GLOBAL: userInfoPane.html]
michael714
  • Contributor

  • 170 posts
  • Corona SDK

I have a couple of suggestions: 

 

1) It is possible you could pass those parameters to Dropbox by appending them to the URL you are sending as opposed to submitting them as headers.   

 

2) If you want to pass them as headers, you should use this form:

 
local params = {}
local headers = {}
headers["Content-Type"] = "text/plain"
headers["Authorization"] = "OAuth "..rawdata
params.headers = headers
local result = network.request( url, "POST", rawPostListener, params)
return result


[TOPIC: post.html]
#31

silvermorph

[GLOBAL: userInfoPane.html]
silvermorph
  • Observer

  • 2 posts
  • Corona SDK

Gotcha - passing them as URL parameters worked perfectly - thanks!



[TOPIC: post.html]
#32

Vince_

[GLOBAL: userInfoPane.html]
Vince_
  • Contributor

  • 305 posts
  • Enterprise

I know this is kind of old, but could somebody please explain how the putFile method works? I don't understand how you pass in the file you want to upload to your dropbox.

 

Thanks!

 

EDIT: Actually I figured it out. For anyone else who might not understand at first this is what you need

-------------------------------------------------
--
--In download.lua
--
-------------------------------------------------
local function networkListener( event )

    if ( event.isError ) then
        print( "Network error!" )
    else
        print ( event.response)
    end
end

local function handleSendEvent( event )
    if ( "ended" == event.phase ) then
        print( "Send button was pressed and released" )

        local path = "<pathtoyourfile>.json" --In my case I needed to sync json
        
        local headers = {}
        headers["Content-Type"] = "application/json"
        
        local params = {}
        params.headers = headers

        -- Tell network.request() to get the request body from a file:
        params.body = {
            filename = path,
            baseDirectory = system.DocumentsDirectory        
        }

        dropbox.putFile( path, networkListener, params )
    end
end

local sendButton = widget.newButton
{
    left = 100,
    top = 400,
    id = "request",
    label = "Send File",
    onEvent = handleSendEvent
}

-------------------------------------------------
--
--In dropboxModule.lua
--
-------------------------------------------------
function M.putFile( path, listener, params )
  local url = "https://api-content.dropbox.com/1/files_put/dropbox/" .. path .. "?" .. authString
  network.request( url, "PUT", listener, params )
end



[TOPIC: post.html]
#33

mark_steelman

[GLOBAL: userInfoPane.html]
mark_steelman
  • Contributor

  • 142 posts
  • Corona SDK

I used your code to create a module that sends a text file to dropbox or downloads one into the app. This works just fine on the Corona emulator and on iOS but it is not working right on Android.

 

I started a thread here:

http://forums.coronalabs.com/topic/55694-networkrequest-not-getting-a-response-from-android/

However, it seems you all might be more likely to know what my issue is.

 

On Android, I can download files but when I try to upload a file the server never responds. My callback doesn't ever fire. I have been messing around with my build.settings file and haven't got it working. I added these permissions: "android.permission.WRITE_EXTERNAL_STORAGE",

"android.permission.ACCESS_NETWORK_STATE",

 

I have also attempted to write an intent filter:

{

       actions = {"android.intent.action.SEND", "android.intent.action.SEND_MULTIPLE"},
       categories = {"android.intent.category.DEFAULT"},
       data = {mimeType="text/plain"}
 }
 
Honestly, I am just kind of guessing on these attempts to fix the problem.
 
The error I'm getting from the device is:
Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1468 com.android.server.InputMethodManagerService$4.run:2747 java.lang.Thread.run:841 <bottom of call stack> <bottom of call stack>
 
Before changing the build.settings I was getting a different error:
Permission Denial: opening provider com.google.android.gsf.gservices.GservicesProvider from ProcessRecord{4471b0e8 25480:com.mycomp.myapp/000000} (pid=00000, uid=00000) requires com.google.android.providers.gsf.permission.READ_GSERVICES or com.google.android.providers.gsf.permission.WRITE_GSERVICES
 
Any advice is appreciated.


[TOPIC: post.html]
#34

abidivi1991

[GLOBAL: userInfoPane.html]
abidivi1991
  • Observer

  • 1 posts
  • Corona SDK

I couldnt get access to this code ,,, could anyone please send me a link, this code description sounds really interesting to work with



[TOPIC: post.html]
#35

michael714

[GLOBAL: userInfoPane.html]
michael714
  • Contributor

  • 170 posts
  • Corona SDK

Did you try this link above:

https://www.dropbox.com/sh/evttsokenvqp7lv/AADr47rIPBq6-HR3Akm7YOyra




[topic_controls]
Page 2 of 2 1 2
 
[/topic_controls]

Also tagged with one or more of these keywords: dropbox, rest, oauth, sample, network