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.

Then, add the following tag under the application tag in your AndroidManifest.xml so as to enable the Activity that the SDK uses for Renren authentication.

<activity
    android:name="com.kii.cloud.storage.social.connector.KiiSocialNetworkConnectorLoginActivity"
    android:label="@string/app_name" />

Logging in with a Renren account

There are two ways to log in with a Renren account.

The latter method (using the login UI) will be discontinued in near future. It is now outside of our support. Use the former method of using a Renren access token.

Using a Renren access token

The following example illustrates how to authenticate a user by using a Renren access token.

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

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

// Set a Renren access token.
option.putString(KiiSocialNetworkConnector.ACCESS_TOKEN, accessToken);

// Authenticate the user to Kii Cloud with the Renren access token.
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 Renren access token. For the detailed instructions, see the Renren official documentation.

  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.RENREN is specified here.

  4. Set the Renren access token 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.

    When an access token is used for the login, all the processing is done in the background with no login screen for Renren. You do not need to implement additional processings that are necessary when using the login UI provided by the SDK. Specifically, you do not need to specify the first parameter Activity of the logIn() method nor add code to the onActivityResult() 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 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");

Using the login UI provided by the SDK (Deprecated)

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

Activity activity = this.getActivity();
KiiSocialConnect connect = Kii.socialConnect(SocialNetwork.SOCIALNETWORK_CONNECTOR);

Bundle options = new Bundle();
options.putParcelable(KiiSocialNetworkConnector.PROVIDER, KiiSocialNetworkConnector.Provider.RENREN);

// Login.
connect.logIn(activity, options, new KiiSocialCallBack() {
  @Override
  public void onLoginCompleted(SocialNetwork network, KiiUser user, Exception exception) {
    if (exception != null) {
      // Handle the error.
      return;
    }
  }
});

The basic steps are as follows.

  1. Create an Activity for handling logging in with a Renren account.
  2. Create a social network connector instance with the socialConnect() method. Here, we are specifying SocialNetwork.SOCIALNETWORK_CONNECTOR.
  3. Create a bundle and specify the target social network service. In this case, we are specifying Provider.RENREN.
  4. Authenticate the user with the logIn() method. If the specified Renren 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.

Note: You also need to add a method to the onActivityResult() method to finish the Renren authentication.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (requestCode == KiiSocialNetworkConnector.REQUEST_CODE) {
    Kii.socialConnect(SocialNetwork.SOCIALNETWORK_CONNECTOR).respondAuthOnActivityResult(
      requestCode,
      resultCode,
      data);
  }
}

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.

// Assume that a user has logged in.

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

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

// Set a Renren access token.
option.putString(KiiSocialNetworkConnector.ACCESS_TOKEN, accessToken);

// Link the Renren 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.RENREN is specified here.

  3. Set a Renren access token to the bundle. For getting a Renren access token, see the Renren official documentation.

  4. Link the currently logged-in user with the Renren 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 Renren account

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

// Assume that a user has logged in.

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

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

// Unlink the Renren 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.RENREN is specified here.

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