Integrating Renren (人人網) Accounts

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

Creating a Renren application

To get started, you first need to create a Renren application and get your Renren (人人網) API key, secret key, and app ID. For the detailed instructions, see the Renren official documentation.

You will need to fill in the following information.

  • Application name
  • Application category
  • Application domain
  • Application description
  • Application icon (16x16, 48x48, 75x75 and 100x100)

When your Renren application is created, you will get a Renren (人人網) API key, secret key, and app ID.

Configuring a Kii application

Take the following steps in the developer portal to configure your application by setting your Renren (人人網) API key, secret key, and app ID.

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

  2. Click "SOCIAL NETWORKS".

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

  4. Set your Renren (人人網) API key, secret key, and app ID.

Logging in with a Renren account

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

  • // Set a Renren access token.
    var options = {
      access_token: __obtained_access_token__
    };
    
    // Authenticate the user to Kii Cloud with the Renren access token.
    KiiSocialConnect.logIn(KiiSocialNetworkName.RENREN, options, {
      success: function(user, network) {
        // Do something.
      },
      failure: function(user, network, errorString) {
        // Handle the error.
      }
    });
  • // Set a Renren access token.
    var options = {
      access_token: __obtained_access_token__
    };
    
    // Authenticate the user to Kii Cloud with the Renren access token.
    KiiSocialConnect.logIn(KiiSocialNetworkName.RENREN, 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 Renren access token. For the detailed instructions, see the Renren official documentation.

  2. Set the Renren access token to the access_token parameter of options.

  3. Authenticate the user with the logIn() method. The first argument specifies the target social network, KiiSocialNetworkName.RENREN. If the specified Renren 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 Renren account

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

Here is the sample code for linking a Kii account to a Renren account. You basically just need to execute the linkCurrentUserWithNetwork() method.

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

  • // Assume that a user has logged in.
    
    // Set a Renren access token.
    var options = {
      access_token: __obtained_access_token__
    };
    
    // Link the Renren account with the currently logged-in Kii user.
    KiiSocialConnect.linkCurrentUserWithNetwork(KiiSocialNetworkName.RENREN, options, {
      success: function(user, network) {
        // Do something.
      },
      failure: function(user, network, errorString) {
        // Handle the error.
      }
    });
  • // Assume that a user has logged in.
    
    // Set a Renren access token.
    var options = {
      access_token: __obtained_access_token__
    };
    
    // Link the Renren account with the currently logged-in Kii user.
    KiiSocialConnect.linkCurrentUserWithNetwork(KiiSocialNetworkName.RENREN, 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 Renren account

Here is the sample code for unlinking a Kii account from a Renren account. You basically just need to execute the unLinkCurrentUserFromNetwork() method.

  • // Assume that a user has logged in.
    
    // Unlink the Renren account from the currently logged-in Kii user.
    KiiSocialConnect.unLinkCurrentUserFromNetwork(KiiSocialNetworkName.RENREN, {
      success: function(user, network) {
        // Do something.
      },
      failure: function(user, network, errorString) {
        // Handle the error.
      }
    });
  • // Assume that a user has logged in.
    
    // Unlink the Renren account from the currently logged-in Kii user.
    KiiSocialConnect.unLinkCurrentUserFromNetwork(KiiSocialNetworkName.RENREN).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;
      }
    );