Dropbox Rest Api Sample Code In Code Exchange

Looks like I still had some older files from a previous version of your bundle in my app’s documents folders, so I removed them, Upon restarting, I press the Connect button and get a response in the terminal. I also get a response in-app via a web pop-up asking if I want to connect to Dropbox. I go ahead, and then press the Get Info button, and again get the error from my last post.

Okay, I got it now. I needed to un-comment this line:

local url = "https://api.dropbox.com/1/account/info"

And then comment out the line two below it. Now the app can retrieve my account data and display it accordingly. Again, nice work on putting this together, michael714!

Glad you got it to work.   Please let me know if there are any changes you think I should make in the file or if there are any comments that I should add.

Thanks for being my alpha tester!

Is there a reason you commented that line out above to get the account info?

I guess I was confused with the getSomething function, because it grabs account info _or_ a file, depending on which line is commented out. You could create a getAccountInfo and getFile function, or just have it grab account info if no argument is passed in, else have the argument be the file name to grab. 

As far as comments to the readme go, it may be worth stating exactly which lines of code need to be changed/appended, as well as where to put the file to “put” on Dropbox. It wasn’t immediately obvious to me that the file needed to go into the Documents folder, instead of in the same folder as my app’s resources. Newbie mistake, but not entirely obvious to me. I think you included a .csv file in an earlier distro - I just used one of the included graphics resources.

I think converting this into a module would be the way to go. Let me know if you don’t plan on it, and maybe I’ll see what I can put together. Not sure how much time I’ll have to work on this this week, but now that the basic Dropbox connection works, I hope to tinker some more and see what else needs to be added.

As a side-note, with the REST API, is the file saved locally automatically when you grab it with getSomething? Does that mean the file needs to be explicitly deleted locally once you’re done? My goal is to read in a bunch of files, but I don’t want them to be saved locally.

Thanks for the response.  I’ll look at this a bit more this weekend.

I played around with this a bit more yesterday and began converting your code into a module. Currently, I have my app connecting to Dropbox, opening up the permissions popup, and reading the contents of a file. I still need to hammer out which functions and such should be exposed, but will hopefully have something a little more concrete this week.

michael 714, if you’re _not_ planning to post this as a module and would like me to post my version, just let me know.

Yes, please, go for it!  I added you as a collaborator on the github repository or you could fork it.  Or, let me know if you would prefer to use another type of revision control system.  

Thanks!

So, how we going?

I’m now looking at how to add DropBox file reading, directory viewing and putting a file up - all this support is fairly basic, but extensive in coding and testing… so would love to jump on the back of someone else’s work to help me along, and of course anything I add or improve, I’d happily post back and contribute.

G

I don’t know that there’s been any progress on the modulization, but the code that’s there will get you started.  You would need to add functionality if you want to upload and download binary files or view the directory.   Give it a  look.

Hey guys - sorry for the silence, but I haven’t had much time to work on this of late. I’m not well-versed with Github, so for now I set up a quick Gist for my code-to-date. It’s still in a pretty rough form and needs a lot of polish, but the core functionality works, thanks to the work pioneered by Michael. https://gist.github.com/WyldKard/5589284

If you have questions about how to utilize the module, drop them here.

So, how we going?

I’m now looking at how to add DropBox file reading, directory viewing and putting a file up - all this support is fairly basic, but extensive in coding and testing… so would love to jump on the back of someone else’s work to help me along, and of course anything I add or improve, I’d happily post back and contribute.

G

I don’t know that there’s been any progress on the modulization, but the code that’s there will get you started.  You would need to add functionality if you want to upload and download binary files or view the directory.   Give it a  look.

Hey guys - sorry for the silence, but I haven’t had much time to work on this of late. I’m not well-versed with Github, so for now I set up a quick Gist for my code-to-date. It’s still in a pretty rough form and needs a lot of polish, but the core functionality works, thanks to the work pioneered by Michael. https://gist.github.com/WyldKard/5589284

If you have questions about how to utilize the module, drop them here.

FWIW, I just updated the gist so the file upload function works properly.

FWIW, I just updated the gist so the file upload function works properly.

@syldkard,

Thanks for posting your code.  Does this only allow for accessing text based files? Or can it “put/get” images, etc?

@syldkard,

Thanks for posting your code.  Does this only allow for accessing text based files? Or can it “put/get” images, etc?

Hi Michael and wildcard. I am keen to put some dropbox functionality into my corona apps and have been reading through your conversations as Michael then wyldkard developed the idea.

I have also been to the dropbox developer site and got me a token and secret and then got the latest code that wyldkard had put in git.

I have been trying to read through the code and I am finding it a bit dense. I suspect that once I understand how it all works then the code will be self explanatory, but at the moment I am finding it hard going. Perhaps a bit more documentation comments in the file??

What is the connection with google.com?

Also in wyldkard’s version I cannot see which functions are called and which are just internal calls. perhaps a short few sentence explanation of how you would use the lua?

for example. I want the user to access their own dropbox from within my app. I have a token and a secret. What do I need to do next in a few lines of code calling on your code?

Hi Both,

Ive been playing a bit more and managed (through trial and error) to get a combination of the lines that were commented out uncommented and the app connects to dropbox, asks for my login then gives me the choice to give permission, then nothing. When I go to my dropbox account there has been some access and a file is there but not the named one.

Is there a version of the file with the correct lines commented that just works?  then I can see where I am going wrong. At the moment it is like blind mans buff.

Martin

Hey guys, sorry for taking so long to respond. I haven’t had a chance to do any coding in the last couple months, so neglected this forum. Have you had any more luck getting this to work? FWIW, the gist I linked to above is the same module I use in my app Str, which uses the module to save files to Dropbox.

rxmarccall: The module should let you put/get files of any type.

martin: I will make an effort to document the steps you need to take to make basic calls to Dropbox once you have your key/secret, and then add them to the gist for easy reference. Once I get that added, I’ll post about it here.

In regards to google.com, the webURL can be anything. Here, google.com is just a placeholder, but feel free to change it to whatever; it’s used here as a callback address, but it doesn’t respond to anything, so it doesn’t matter what you use,

This was actually my first Lua module, so I apologize if I broke expected standards. Any functions with “local” in front of them are internal. The other functions are external and should be called from your main code - basically all functions from M.connect() onward.

I don’t have my code in front of me, but from recollection, from your main app be sure to import the Dropbox.lua module. Call the connect() function and pass it your key and secret for your respective Dropbox app, as well as “root” or “sandbox” depending on what level of Dropbox access you want to give your app. The first time you do this, your app will pop up a web view requesting you to log in to your Dropbox account.

Once that’s done, you can call the other functions to access your Dropbox. Best way to verify things are working is to call the getAccount() function which should print your account info to the console. If you’re getting the correct response here, you can go ahead and use the get/put functions but you have to specify a listener in your main code so your app does something with the response. Let me know if you need more help with that and I’ll post an example.