Integrating QQ Accounts

This topic explains how to allow your users to sign up for and log in to your mobile app with their QQ 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 QQ integration

Creating a QQ application

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

Configuring a Kii application

Take the following steps in the developer portal to configure your application by setting your QQ app ID.

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

  2. Click "SOCIAL NETWORKS".

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

  4. Set your QQ app ID.

Logging in with a QQ account

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

Swift 3:

func myRegistrationMethod(){
  // Set a QQ access token and a QQ OpenID.
  let options : Dictionary = ["accessToken":accessToken,"openID":openid]

  // Authenticate the user to Kii Cloud with the QQ access token and the QQ OpenID.
  KiiSocialConnect.log(in: .QQ, options: options) { (retUser :KiiUser?, provider : KiiConnectorProvider, retError : Error? ) -> Void in
    if (retError != nil) {
      // Handle the error.
      return
    }
  }
}

Objective-C:

- (void)myRegistrationMethod {
  // Set a QQ access token and a QQ OpenID.
  NSDictionary *options = @{@"accessToken":accessToken, @"openID":openid};

  // Authenticate the user to Kii Cloud with the QQ access token and the QQ OpenID.
  [KiiSocialConnect logIn:kiiConnectorQQ
                  options:options
                    block:^(KiiUser *retUser, KiiConnectorProvider provider, NSError *retError) {
    if (retError != nil) {
      // Handle the error.
      return;
    }
  }];
}

The basic steps are as follows.

  1. Get a QQ access token and OpenID. For the detailed instructions, see the QQ official documentation.

    Note: Make sure that your app gets the permission of get_user_info from the user when logging in the QQ account via the QQ SDK (For more information, see the QQ official documentation). It is required for Kii Cloud to access the QQ user profile for the login process. Also, handle the case when the QQ user doesn't give this permission to your app.

  2. Set the QQ access token and OpenID to the accessToken and openID parameters of options.

  3. Authenticate the user with the logIn:options:block: method. The first argument specifies the target social network, kiiConnectorQQ. If the specified QQ 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:

// Get the token dictionary for the social network provider.
let dict  = KiiSocialConnect.accessTokenDictionary(.QQ)! as NSDictionary

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

// Get the OpenID.
let openID = (dict.object(forKey: "openID") as? String)!

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

// Check if a new Kii user was created when the log(in:options:_:) method was executed.
let kiiNewUser : Bool = (dict.object(forKey: "kii_new_user") as? NSNumber)!.boolValue

Objective-C:

// Get the token dictionary for the social network provider.
NSDictionary *dict = [KiiSocialConnect accessTokenDictionary:kiiConnectorQQ];

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

// Get the OpenID.
NSString *openID = [dict objectForKey:@"openID"];

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

// Check if a new Kii user was created when the logIn:options:block: method was executed.
BOOL kiiNewUser = [dict valueForKey:@"kii_new_user"];

Linking a Kii account to a QQ account

You can link existing Kii users to their QQ accounts. Linked users can log in to Kii Cloud via the QQ authentication.

Here is the sample code for linking a Kii account to a QQ account. You basically just need to execute the linkCurrentUser:options:block: method.

Note that this sample code assumes that your mobile app has obtained a QQ access token and OpenID. For getting them, see the QQ official documentation.

Swift 3:

// Assume that a user has logged in.

func myAccountLinkMethod(){
  // Set a QQ access token and a QQ OpenID.
  let options : Dictionary = ["accessToken":accessToken,"openID":openid]

  // Link the QQ account with the currently logged-in Kii user.
  KiiSocialConnect.linkCurrentUser(.QQ, options: options) { (retUser :KiiUser?, provider : KiiConnectorProvider, retError : Error? ) -> Void in
    if (retError != nil) {
      // Handle the error.
      return
    }
  }
}

Objective-C:

// Assume that a user has logged in.

- (void) myAccountLinkMethod {
  // Set a QQ access token and a QQ OpenID.
  NSDictionary *options = @{
    @"access_token":accessToken,
    @"openID":openid
  }

  // Link the QQ account with the currently logged-in Kii user.
  [KiiSocialConnect linkCurrentUser:kiiConnectorQQ
                            options:options
                              block:^(KiiUser *retUser, KiiConnectorProvider provider, NSError *retError) {
    if (retError != nil) {
      // Handle the error.
      return;
    }
  }];
}

Unlinking a Kii account from a QQ account

Here is the sample code for unlinking a Kii account from a QQ account. You basically just need to execute the unLinkCurrentUser:options:block: method.

Swift 3:

// Assume that a user has logged in.

func myAccountUnlinkMethod(){
  // Unlink the QQ account from the currently logged-in Kii user.
  KiiSocialConnect.unLinkCurrentUser(.QQ) { (retUser :KiiUser?, provider : KiiConnectorProvider, retError : Error? ) -> Void in
    if (retError != nil) {
      // Handle the error.
      return
    }
  }
}

Objective-C:

// Assume that a user has logged in.

- (void) myAccountUnlinkMethod {
  // Unlink the QQ account from the currently logged-in Kii user.
  [KiiSocialConnect unLinkCurrentUser:kiiConnectorQQ
                                block:^(KiiUser *retUser, KiiConnectorProvider provider, NSError *retError) {
    if (retError != nil) {
      // Handle the error.
      return;
    }
  }];
}