Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Codea DropBox tutorial

edited March 2013 in General Posts: 666

I've put together a write-up of how I connected DropBox to Codea inside an app. It can be found here:
http://uptwolate.blogspot.com/2013/03/dropbox-integration-in-codea.html

Comments

  • BriarfoxBriarfox Mod
    Posts: 1,542

    I keep getting "The Request to Link the App is Invalid" on the dropbox page

  • Posts: 666

    @BriarFox, did you make an app in DropBox first? If so, you have a key/secret that you pass to the DropBox constructor.

    What does your main() look like?

  • BriarfoxBriarfox Mod
    Posts: 1,542

    Yeah I setup an app on the dev page. Called it CodeaDB. I've entered and re-entered the key and secret.

    main is

    function setup()
    
        --displayMode(FULLSCREEN)
        --the app info to connect to. These come from your DropBox app developer page. 
        --I am not giving my key out in an open forum!
        appKey = "v1*************"  --app key
        appSecret = "sa*************"  --app secret
        db = DropBox(appKey, appSecret)
    
  • Posts: 666

    That looks right. I'm going to ASSUME you didn't make a mistake with the keys.

    I also just validated that I can still use DropBox integration on 1.5, it was OK, though it gave me a warning because I'm using http.get().

    Keep in mind that you had to go through all three steps. So, which step are you getting stopped at?

  • BriarfoxBriarfox Mod
    Posts: 1,542

    aciolino, i must have made a mistake. I re coppied and pasted and it worked! Very neat code. thanks for sharing it. its going to be very useful.

  • Posts: 666

    You're welcome! Glad it's working!

  • Jmv38Jmv38 Mod
    Posts: 3,297

    Very interesting work @Aciolino. Thanks for sharing.

  • BriarfoxBriarfox Mod
    edited March 2013 Posts: 1,542

    I was having an issue reading the key and the secret from storage. It always required the variable appKey and appSecret in main.lua

    I added self.appKey and self.appSecret to line 51 &52 of DropBox.lua

       assert(self.appKey ~= nil, "You must assign a DropBox application before accessng DropBox.")
        assert(self.appSecret ~= nil, "You must assign a DropBox application before accessng DropBox.")
    
    
  • IgnatzIgnatz Mod
    edited March 2013 Posts: 5,396

    I went through all the steps and set up Dropbox, and put my keys in your code, but it's the final stage that confuses me a little

    I set up Main like this

    function setup()
        d=DropBox()
        d:GetRequestToken()
        d:DoAuthorize()
        d:GetAcccessToken()
    end
    

    This opened up an approval request in Safari, which I authorised. After a few seconds I went back to Codea, which was showing this:

    Ready to GetAccessToken
    error: [string "function setup()..."]:5: attempt to call method 'GetAcccessToken' (a nil value)
    Ready to authorize
    

    Am I supposed to do something back in Codea? And if I get this working, do I have to go through this authorization every time I use Dropbox, or is it one time? Sorry about all the questions!

  • BriarfoxBriarfox Mod
    Posts: 1,542

    Just run the main.lua from the gist to set it up. then link to your project. All i did in my project was:

    db = DropBox() -- I set the key and secret in global so i pass nothing.
    db:Write(name,data)
    

    and it worked

  • IgnatzIgnatz Mod
    Posts: 5,396

    It's ok, I'm an idiot. I copied and pasted from the gist page, not realizing there were three files to copy. Now it works. And it's cool.

  • BriarfoxBriarfox Mod
    Posts: 1,542

    @Ignatz, grab one of the gist loaders and pull from gist directly into codea.

  • IgnatzIgnatz Mod
    Posts: 5,396

    @aciolino I've built this function to create backups only when the version number changes, so you can safely call it in setup at the start of each run, knowing it isn't going to clutter your Dropbox account or write over your last good backup. It stores backups in a Backup folder (deleting any extra copies made in the root folder as well). The only issue is that it requires an awful lot of support code (DropBox plus JSON), so I suppose if I use this in practice, I'll set references to a separate Dropbox project rather than importing it. Improvements welcome.

    function DropBox:Backup(proj,ver) -- proj=project name, ver=version number
        if ver~=readProjectData("Version") then
            local tabs=listProjectTabs()
            local txt=""
            for i=1,#tabs do
                if tabs[i]~="DropBox" and tabs[i]~="JSON" then
                    txt=txt..readProjectTab(tabs[i])
                end
            end
            fName=proj.."_"..ver..".txt"
            self:Write(fName, txt, function() 
                self:Copy("/"..fName, "/Backup/"..fName, 
                    function() print("Version "..ver.." backed up") end)      
                    saveProjectData("Version",ver)
                 self:Delete("/"..fName, callback)
            end)
        end
    end
    
  • Posts: 666

    Just so that you know, DropBox checks to see if your file is different and if it's not, it doesn't update it...I think...

  • IgnatzIgnatz Mod
    edited March 2013 Posts: 5,396

    Thank you - but that doesn't affect why I did it this way. If I'm tinkering with a project, I may try something out, find it doesn't work, and want to go back to how it was before. If Codea keeps overwriting my latest version every time I make a change, I will have nothing to go back to. So I want my backups to be at specific checkpoints.

  • Jmv38Jmv38 Mod
    Posts: 3,297

    To keek intermediate versions, i long press on the project, and make a copy with a version number at the end of the name.

  • Posts: 666

    Lol - version control! Who needs it!?

    Actually, the version number idea is pretty good, though I usually do a backup to DropBox, then on a PC, zip the directories with today's date.

Sign In or Register to comment.