Checking the Social Network Integration Status
Getting a list of integrated services
The following sample shows how you can get a list of social network services currently being linked to the user.
Swift:
-
let userURI = "Set the URI of an existing user here" // Instantiate a user. let userWithURI = KiiUser(uri: userURI) do{ // Refresh the user. try userWithURI.refreshSynchronous() } catch let error as NSError { // Handle the error. return } // Get social network accounts linked to the user. for (_,value) in userWithURI.linkedSocialAccounts { let info = value as! KiiSocialAccountInfo print("Provider Code : \(info.provider)") print("Created at : \(info.createdAt)") print("Social AccountId code: \(info.socialAccountId)") }
-
let userUri = "Set the URI of an existing user here" // Instantiate a user. let userWithURI = KiiUser(uri: userURI) // Refresh the user. userWithURI.refresh { (user : KiiUser?, error : Error?) -> Void in if error != nil { // Handle the error. return } // Get social network accounts linked to the user. for (_,value) in userWithURI.linkedSocialAccounts { let info = value as! KiiSocialAccountInfo print("Provider Code : \(info.provider)") print("Created at : \(info.createdAt)") print("Social AccountId code: \(info.socialAccountId)") } }
Objective-C:
-
NSString *userURI = @"Set the URI of an existing user here"; // Instantiate a user. KiiUser *userWithURI = [KiiUser userWithURI:userURI]; NSError* error = nil; // Refresh the user. [userWithURI refreshSynchronous:&error]; if (error != nil) { // Handle the error. return; } // Get social network accounts linked to the user. [[userWithURI linkedSocialAccounts] enumerateKeysAndObjectsUsingBlock:^(NSString *key, KiiSocialAccountInfo *info, BOOL *stop) { NSLog(@"Provider code: %@", @(info.provider)); NSLog(@"Created At: %@", info.createdAt); NSLog(@"Social AccountId code: %@", info.socialAccountId); }];
-
NSString *userURI = @"Set the URI of an existing user here"; // Instantiate a user. KiiUser *userWithURI = [KiiUser userWithURI:userURI]; // Refresh the user to get the latest user info from Kii Cloud. [userWithURI refreshWithBlock:^(KiiUser *user, NSError *error) { if (error != nil) { // Handle the error. return; } // Get social network accounts linked to the user. [[userWithURI linkedSocialAccounts] enumerateKeysAndObjectsUsingBlock:^(NSString *key, KiiSocialAccountInfo *info, BOOL *stop) { NSLog(@"Provider code: %@", @(info.provider)); NSLog(@"Created At: %@", info.createdAt); NSLog(@"Social AccountId code: %@", info.socialAccountId); }]; }];
Checking if a service is already integrated
The following sample code shows how you can check if the specified social network service is already linked to the user.
Swift:
-
// Instantiate a user. let user = KiiUser(uri: "Set the URI of an existing user here") do{ // Refresh the user. try user.refreshSynchronous() } catch let error as NSError { // Handle the error. return } if user.isLinked(withSocialProvider: .Facebook) { // A Facebook account is linked to this user. } if user.isLinked(withSocialProvider: .Twitter) { // A Twitter account is linked to this user. }
-
// Instantiate a user. let user = KiiUser(uri: "Set the URI of an existing user here") // Refresh the user. userWithURI.refresh { (user : KiiUser?, error : Error?) -> Void in if error != nil { // Handle the error. return } if user.isLinked(withSocialProvider: .Facebook) { // A Facebook account is linked to this user. } if user.isLinked(withSocialProvider: .Twitter) { // A Twitter account is linked to this user. } }
Objective-C:
-
// Instantiate a user. KiiUser *user = [KiiUser userWithURI:@"Set the URI of an existing user here"]; NSError *error = nil; // Refresh the user. [user refreshSynchronous:&error]; if (error != nil) { // Handle the error. return; } if ([user isLinkedWithSocialProvider:kiiConnectorFacebook]) { // A Facebook account is linked to this user. } if ([user isLinkedWithSocialProvider:kiiConnectorTwitter]) { // A Twitter account is linked to this user. }
-
// Instantiate a user. KiiUser *user = [KiiUser userWithURI:@"Set the URI of an existing user here"]; // Refresh the user to get the latest user info from Kii Cloud. [userWithURI refreshWithBlock:^(KiiUser *user, NSError *error) { if (error != nil) { // Handle the error. return; } if ([user isLinkedWithSocialProvider:kiiConnectorFacebook]) { // A Facebook account is linked to this user. } if ([user isLinkedWithSocialProvider:kiiConnectorTwitter]) { // A Twitter account is linked to this user. } }];