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

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

// Create a KiiSocialConnect instance.
KiiSocialConnect connect = Kii.socialConnect(KiiSocialConnect.SocialNetwork.SOCIALNETWORK_CONNECTOR);

// Specify QQ as the social network provider for logging in to Kii Cloud.
Bundle option = new Bundle();
option.putParcelable(KiiSocialNetworkConnector.PROVIDER, KiiSocialNetworkConnector.Provider.QQ);

// Set a QQ access token and a QQ OpenID.
option.putString(KiiSocialNetworkConnector.ACCESS_TOKEN, accessToken);
option.putString(KiiSocialNetworkConnector.OPEN_ID, openID);

// Authenticate the user to Kii Cloud with the QQ access token and the QQ OpenID.
connect.logIn(null, option, new KiiSocialCallBack() {
  @Override
  public void onLoginCompleted(KiiSocialConnect.SocialNetwork network, KiiUser user, Exception exception) {
    if (exception != null) {
      // 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. Create an instance of a social network connector with the socialConnect() method. The argument is KiiSocialConnect.SocialNetwork.SOCIALNETWORK_CONNECTOR.

  3. Create a Bundle instance and specify the target social network. Provider.QQ is specified here.

  4. Set the QQ access token and OpenID to the bundle.

  5. Authenticate the user with the logIn() method. If the specified account is new to Kii Cloud, the user is registered before the login. The logIn() 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 getCurrentUser() method. You can also retrieve the access token and related parameters with the getAccessTokenBundle() method as follows:

// Get the token bundle for the social network provider.
KiiSocialConnect connect = Kii.socialConnect(SocialNetwork.SOCIALNETWORK_CONNECTOR);
Bundle b = connect.getAccessTokenBundle();

// Get the access token.
String accessToken = b.getString("oauth_token");

// Get the OpenID.
String openID = b.getString("openID");

// Get the user ID provided by the social network provider.
String providerUserId = b.getString("provider_user_id");

// Check if a new Kii user was created when the logIn() method was executed.
boolean kiiNewUser = b.getBoolean("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.

// Assume that a user has logged in.

// Create a KiiSocialConnect instance.
KiiSocialConnect connect = Kii.socialConnect(KiiSocialConnect.SocialNetwork.SOCIALNETWORK_CONNECTOR);

// Specify QQ as the social network provider for logging in to Kii Cloud.
Bundle option = new Bundle();
option.putParcelable(KiiSocialNetworkConnector.PROVIDER, KiiSocialNetworkConnector.Provider.QQ);

// Set a QQ access token and a QQ OpenID.
option.putString(KiiSocialNetworkConnector.ACCESS_TOKEN, accessToken);
option.putString(KiiSocialNetworkConnector.OPEN_ID, openID);

// Link the QQ account with the currently logged-in Kii user.
connect.link(null, option, new KiiSocialCallBack() {
  @Override
  public void onLinkCompleted(KiiSocialConnect.SocialNetwork network, KiiUser user, Exception exception) {
    if (exception != null) {
      // Handle the error.
      return;
    }
  }
});

The basic steps are as follows.

  1. Create an instance of a social network connector with the socialConnect() method. The argument is KiiSocialConnect.SocialNetwork.SOCIALNETWORK_CONNECTOR.

  2. Create a Bundle instance and specify the target social network. Provider.QQ is specified here.

  3. Set a QQ access token and OpenID to the bundle. For getting them, see the QQ official documentation.

  4. Link the currently logged-in user with the QQ account with the link() method. This method is non-blocking and receives the processing result in the callback method.

Unlinking a Kii account from a QQ account

Here is the sample code for unlinking a Kii account from a QQ account.

// Assume that a user has logged in.

// Create a KiiSocialConnect instance.
KiiSocialConnect connect = Kii.socialConnect(KiiSocialConnect.SocialNetwork.SOCIALNETWORK_CONNECTOR);

// Specify QQ as the social network provider for logging in to Kii Cloud.
Bundle option = new Bundle();
option.putParcelable(KiiSocialNetworkConnector.PROVIDER, KiiSocialNetworkConnector.Provider.QQ);

// Unlink the QQ account from the currently logged-in Kii user.
connect.unlink(null, option, new KiiSocialCallBack() {
  @Override
  public void onUnLinkCompleted(KiiSocialConnect.SocialNetwork network, KiiUser user, Exception exception) {
    if (exception != null) {
      // Handle the error.
      return;
    }
  }
});

The basic steps are as follows.

  1. Create an instance of a social network connector with the socialConnect() method. The argument is KiiSocialConnect.SocialNetwork.SOCIALNETWORK_CONNECTOR.

  2. Create a Bundle instance and specify the target social network. Provider.QQ is specified here.

  3. Unlink the currently logged-in user from the QQ account with the unlink() method. This method is non-blocking and receives the processing result in the callback method.