Integrating QQ Accounts

This topic explains how to allow your users to sign up and log in with their QQ accounts. All you need to do is add a configuration value via the dev portal and add a few line of code to your app!

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

The following example illustrates how to authenticate a user with their QQ account:

  • // Set a QQ access token and a QQ OpenID.
    var options = {
      access_token: __obtained_access_token__,
      openID: __obtained_open_id__
    };
    
    // Authenticate the user to Kii Cloud with the QQ access token and the QQ OpenID.
    KiiSocialConnect.logIn(KiiSocialNetworkName.QQ, options, {
      success: function(user, network) {
        // Do something.
      },
      failure: function(user, network, errorString) {
        // Handle the error.
      }
    });
  • // Set a QQ access token and a QQ OpenID.
    var options = {
      access_token: __obtained_access_token__,
      openID: __obtained_open_id__
    };
    
    // Authenticate the user to Kii Cloud with the QQ access token and the QQ OpenID.
    KiiSocialConnect.logIn(KiiSocialNetworkName.QQ, options).then(
      function(params) {
        var user = params[0];
        var network = params[1];
        // Do something.
      }
    ).catch(
      function(error) {
        // Handle the error.
        var errorString = error.message;
        var network = error.network;
      }
    );

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 access_token and openID parameters of options.

  3. Authenticate the user with the logIn() method. The first argument specifies the target social network, KiiSocialNetworkName.QQ. If the specified QQ account is new to Kii Cloud, the user is registered before the login.

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 KiiUser.getCurrentUser() method.

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 Q authentication.

Here is the sample code for linking a Kii account to a QQ account. You basically just need to execute the linkCurrentUserWithNetwork() 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.

  • // Assume that a user has logged in.
    
    // Set a QQ access token and a QQ OpenID.
    var options = {
      access_token: __obtained_access_token__,
      openID: __obtained_open_id__
    };
    
    // Link the QQ account with the currently logged-in Kii user.
    KiiSocialConnect.linkCurrentUserWithNetwork(KiiSocialNetworkName.QQ, options, {
      success: function(user, network) {
        // Do something.
      },
      failure: function(user, network, errorString) {
        // Handle the error.
      }
    });
  • // Assume that a user has logged in.
    
    // Set a QQ access token and a QQ OpenID.
    var options = {
      access_token: __obtained_access_token__,
      openID: __obtained_open_id__
    };
    
    // Link the QQ account with the currently logged-in Kii user.
    KiiSocialConnect.linkCurrentUserWithNetwork(KiiSocialNetworkName.QQ, options).then(
      function(params) {
        var user = params[0];
        var network = params[1];
        // Do something.
      }
    ).catch(
      function(error) {
        // Handle the error.
        var user = error.target;
        var errorString = error.message;
        var network = error.network;
      }
    );

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 unLinkCurrentUserFromNetwork() method.

  • // Assume that a user has logged in.
    
    // Unlink the QQ account from the currently logged-in Kii user.
    KiiSocialConnect.unLinkCurrentUserFromNetwork(KiiSocialNetworkName.QQ, {
      success: function(user, network) {
        // Do something.
      },
      failure: function(user, network, errorString) {
        // Handle the error.
      }
    });
  • // Assume that a user has logged in.
    
    // Unlink the QQ account from the currently logged-in Kii user.
    KiiSocialConnect.unLinkCurrentUserFromNetwork(KiiSocialNetworkName.QQ).then(
      function(params) {
        var user = params[0];
        var network = params[1];
        // Do something.
      }
    ).catch(
      function(error) {
        // Handle the error.
        var user = error.target;
        var errorString = error.message;
        var network = error.network;
      }
    );