Search code examples
iosdropbox

Dropbox Sync API AccessToken


When I used the core API I simply used the code

[dbsession updateAccessToken:@"..." accessTokenSecret:@"..." forUserId:@"..."];

to access my dropbox account from any copy of the app. But now I found out of this new Sync API that is easier and more flexible, but I didn't find any equivalent for the code displayed above. It now is:

DBAccountManager* accountMgr = [[DBAccountManager alloc] initWithAppKey:@"..." secret:@"..."];
[DBAccountManager setSharedManager:accountMgr];

??[DBAccountManager updateAccessToken:@"..." accessTokenSecret:@"..." forUserId:@"..."];??

How can I access my account? Where can I insert the AccessToken?


Solution

  • From your question, it seems that this method on DBAccountManager is the one for using your appKey and secret:

    - (id)initWithAppKey:(NSString *)key secret:(NSString *)secret
    

    From the documentation description, it says this method "...create[s] a new account manager with your app’s app key and secret. You can register your app or find your key at the apps page."

    After you create an instance of DBAccountManager and set it to be the shared manager using [DBAccountManager setSharedManager:], you can login the specific user by calling this method:

    [[DBAccountManager sharedManager] linkFromController:YOUR_ROOT_CONTROLLER];
    

    Here's a description from the dropbox iOS tutorial:

    "To start interacting with the Sync API, you'll need to create a DBAccountManager object. This object lets you link to a Dropbox user's account which is the first step to working with data on their behalf"

    "...the linking process will switch to the Dropbox mobile app if it's installed. Once the user completes the authorization step, Dropbox will redirect them back to your app using the URL scheme you registered when setting up the SDK. Your app needs to handle those requests to complete the auth flow."

    The final step as mentioned in the tutorial is to handle the redirect. Here's some code to do this:

    - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url sourceApplication:(NSString *)source annotation:(id)annotation {
        DBAccount *account = [[DBAccountManager sharedManager] handleOpenURL:url];
        if (account) {
            NSLog(@"App linked successfully!");
            return YES;
        }
    }
    

    The user's account information can now be obtained through [DBAccountManager sharedManager].linkedAccount which is a DBAccount with properties like userId and accountInfo.

    Here's a link to the docs for reference. Hope this helps!

    Update

    It seems I may have misunderstood your question. I am giving you instructions on how to use the Sync API and didn't quite clarify that there is actually no place for a user's accessToken in the API. This has been replaced with the web flow that I describe above.