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 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

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.

Swift 3:

func myRegistrationMethod(){
  // Set a Renren access token.
  let options : Dictionary = ["accessToken":accessToken]

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

Objective-C:

- (void)myRegistrationMethod {
  // Set a Renren access token.
  NSDictionary *options = @{@"accessToken":accessToken};

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

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

  3. Authenticate the user with the logIn:options:block: method. The first argument specifies the target social network, kiiConnectorRenren. If the specified Renren 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(.Renren)! as NSDictionary

// Get the access token.
let accessToken = (dict.object(forKey: "oauth_token") 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:kiiConnectorRenRen];

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

// 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"];

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:

Swift 3:

func myRegistrationMethod(){
  // Set options to nil to indicate that SDK will handle the UI
  let options : Dictionary<String,AnyObject>? = nil

  //Login

  KiiSocialConnect.log(in: .Renren, options: options) { (retUser :KiiUser?, provider : KiiConnectorProvider, retError : Error? ) -> Void in
    if (retError != nil) {
      // Handle the error.
      return
    }
    // The user has logged in successfully
  }
}

Objective-C:

- (void)myRegistrationMethod {
  // Set options to nil to indicate that SDK will handle the UI
  NSDictionary *options = nil;

  // Login.
  [KiiSocialConnect logIn:kiiConnectorRenRen
                  options:options
                    block:^(KiiUser *retUser, KiiConnectorProvider provider, NSError *retError) {
    if (retError != nil) {
      // Handle the error.
      return;
    }
    // The user has logged in successfully
  }];
}

The basic steps are as follows.

  1. Set nil to options to specify the authentication mechanism.
  2. Authenticate the user with the logIn:options:block: method. If the specified Renren 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.

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 linkCurrentUser:options:block: 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.

Swift 3:

// Assume that a user has logged in.

func myAccountLinkMethod(){
  // Set a Renren access token.
  let options : Dictionary = ["accessToken":accessToken]

  // Link the Renren account with the currently logged-in Kii user.
  KiiSocialConnect.linkCurrentUser(.Renren, 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 Renren access token.
  NSDictionary *options = @{
    @"access_token":accessToken
  }

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

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 unLinkCurrentUser:options:block: method.

Swift 3:

// Assume that a user has logged in.

func myAccountUnlinkMethod(){
  // Unlink the Renren account from the currently logged-in Kii user.
  KiiSocialConnect.unLinkCurrentUser(.Renren) { (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 Renren account from the currently logged-in Kii user.
  [KiiSocialConnect unLinkCurrentUser:kiiConnectorRenRen
                                block:^(KiiUser *retUser, KiiConnectorProvider provider, NSError *retError) {
    if (retError != nil) {
      // Handle the error.
      return;
    }
  }];
}