Integrating Dropbox Accounts

This topic explains how to allow your users to sign up for and log in to your mobile app with their Dropbox account. Just add a few parameters in the developer portal and a few lines of code in your mobile app and you will be social-ready!

Configuring Dropbox integration

Creating a Dropbox application

To get started, you first need to create a Dropbox application and get your Dropbox app key and app secret. For the detailed instructions, see the Dropbox official documentation.

You will need to fill in the following information.

  • What type of app do you want to create? (Please select "Dropbox API app")
  • What type of data does your app need to store on Dropbox? (Please select "Datastores only")
  • Provide an app name, and you're on your way. (Please put your application name)

When your Dropbox application is created, you will get a Dropbox app key and app secret.

Next, please configure your application. In "Redirect URIs", please specify the value that corresponds to the server location you've selected (please put your AppID in ${your-app-id}).

  • "Settings" > "OAuth2" > "Redirect URIs"
    • United States: https://${your-app-id}.us.kiiapps.com/api/apps/${your-app-id}/integration/webauth/callback
    • Japan: https://${your-app-id}.jp.kiiapps.com/api/apps/${your-app-id}/integration/webauth/callback
    • Singapore: https://${your-app-id}.sg.kiiapps.com/api/apps/${your-app-id}/integration/webauth/callback
    • Europe: https://${your-app-id}.eu.kiiapps.com/api/apps/${your-app-id}/integration/webauth/callback

Configuring a Kii application

Take the following steps in the developer portal to configure your application by setting your Dropbox app key and app secret.

  1. Click on the "Edit" button in your application console in the developer portal.

  2. Click "SOCIAL NETWORKS".

  3. Click "Dropbox" to open the configuration screen for Dropbox.

  4. Set your Dropbox app key and app secret.

Logging in with a Dropbox account

Here is the sample code for letting a new user log in with their Dropbox account:

Swift 3:

func myRegistrationMethod(){
  // Set options to nil to indicate that SDK will handle the UI
  let options : Dictionary<String,AnyObject>? = nil

  //Login

  KiiSocialConnect.log(in: .Dropbox, options: options) { (retUser :KiiUser?, provider : KiiConnectorProvider, retError : Error? ) -> Void in
    if (retError != nil) {
      // Handle the error.
      return
    }
    // The user has logged in successfully
  }
}

Objective-C:

- (void)myRegistrationMethod {
  // Set options to nil to indicate that SDK will handle the UI
  NSDictionary *options = nil;

  // Login.
  [KiiSocialConnect logIn:kiiConnectorDropbox
                  options:options
                    block:^(KiiUser *retUser, KiiConnectorProvider provider, NSError *retError) {
    if (retError != nil) {
      // Handle the error.
      return;
    }
    // The user has logged in successfully
  }];
}

The basic steps are as follows.

  1. Set nil to options to specify the authentication mechanism.
  2. Authenticate the user with the logIn:options:block: method. If the specified Dropbox account is new to Kii Cloud, the user is registered before the login. The logIn:options:block: method is non-blocking and receives the processing result with the callback method.

If the login is successful, the user is cached inside the SDK as the current user and you can get the user information with the currentUser method. You can also retrieve the access token and related parameters with the accessTokenDictionary: method as follows:

Swift 3:

let dict  = KiiSocialConnect.accessTokenDictionary(.Dropbox)! as NSDictionary

// The access token.
let accessToken = (dict.object(forKey: "oauth_token") as? String)!

// User id provided by the social network provider.
let providerUserId = (dict.object(forKey: "provider_user_id") as? String)!

// If a new Kii user is created with the logIn method.
let kiiNewUser : Bool = (dict.object(forKey: "kii_new_user") as? NSNumber)!.boolValue

Objective-C:

NSDictionary *dict = [KiiSocialConnect accessTokenDictionary:kiiConnectorLive];

// The access token.
NSString *accessToken = [dict objectForKey:@"oauth_token"];

// User id provided by the social network provider.
NSString *providerUserId = [dict objectForKey:@"provider_user_id"];

// If a new Kii user is created with the logIn method.
BOOL kiiNewUser = [dict valueForKey:@"kii_new_user"];