外部サービス連携状況の確認

連携している外部サービス一覧の取得

ユーザーにリンクされている外部サービスを取得する例を以下に挙げます。

Swift 3:

  • 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);
      }];
    }];

連携している外部サービスの確認

以下のように外部サービスを指定してリンク済みかどうかを確認できます。

Swift 3:

  • // 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.
      }
    }];