Search code examples
actionscript-3apache-flexairdropboxblackberry-playbook

Adobe Air and Dropbox


I'm trying to integrate dropbox into my BB Playbook app using adobe air in flashbuilder 4.6. I got the API from http://code.google.com/p/dropbox-as3/wiki/EXAMPLES and I'm also using that example.

public function getRequestToken():void
{
    dropAPI.requestToken();
    var handler:Function = function (evt:DropboxEvent):void
    {
            dropAPI.removeEventListener(DropboxEvent.REQUEST_TOKEN_RESULT, handler);
            var obj:Object = evt.resultObject;
            reqTokenKeyLabel.text = obj.key;
            reqTokenSecretLabel.text = obj.secret;
            // goto authorization web page to authorize, after that, call get access token 
            if (oauthRadioBtn.selected) {
                    Alert.show(dropAPI.authorizationUrl);
            }
    };
    dropAPI.addEventListener(DropboxEvent.REQUEST_TOKEN_RESULT, handler);
    if (!dropAPI.hasEventListener(DropboxEvent.REQUEST_TOKEN_FAULT)) {
            dropAPI.addEventListener(DropboxEvent.REQUEST_TOKEN_FAULT, faultHandler);
    }
}

This executes as expected but I don't know how to go further, I tried sending the user to the link generated and I allow the application but the get access token still fails. I feel like there is missing code, how does my application know what the access token is? should I not be getting something back from dropbox when the user allows the application?


Solution

  • Once the user has accepted the app in the web browser you should call this function in order to get the access token and secret:

    public function getAccessToken():void{
    
        dropAPI.accessToken();
        var handler:Function = function (evt:DropboxEvent):void{
            dropAPI.removeEventListener(DropboxEvent.ACCESS_TOKEN_RESULT, handler);
            var obj:Object = evt.resultObject;
            myAccessToken = obj.key;
            myAccessSecret = obj.secret;
        };
        dropAPI.addEventListener(DropboxEvent.ACCESS_TOKEN_RESULT, handler);
        if (!dropAPI.hasEventListener(DropboxEvent.ACCESS_TOKEN_FAULT)) {
            dropAPI.addEventListener(DropboxEvent.ACCESS_TOKEN_FAULT, faultHandler);
        }
    }
    

    Once you have them you can save them for future use. After that you have establish connection with Dropbox.

    I hope this will help you