# Unity SDK\_第三方账户关联

可以在一个游戏账户中关联或解除关联多个第三方账户。

&#x20;

## 账户关联功能 <a href="#zhang-hu-guan-lian-gong-neng" id="zhang-hu-guan-lian-gong-neng"></a>

***

如要使用Google、Facebook、NAVER等第三方账户的关联功能，请使用下列代码。

&#x20;

* 方式1

  ```
  public enum LinkingType
  {
      GOOGLEPLAY,
      GAMECENTER,
      GOOGLE,
      FACEBOOK,
      NAVER,
      TWITTER,
      LINE,
      APPLE
  }

  void GamePot.createLinking(NCommon.LinkingType.XXXXX);

  /// 取消账户关联
  public void onCreateLinkingCancel() {
      // 用户取消账户关联
  }

  /// 账户关联成功
  public void onCreateLinkingSuccess(NUserInfo userInfo) {
  }

  /// 账户关联失败
  public void onCreateLinkingFailure(NError error) {
      // 请使用error.message显示错误消息。
  }
  ```

* 方式2

  ```
  public enum LinkingType
  {
      GOOGLEPLAY,
      GAMECENTER,
      GOOGLE,
      FACEBOOK,
      NAVER,
      TWITTER,
      LINE,
      APPLE
  }

  void GamePot.createLinking(NCommon.LinkingType.XXXXX, GamePotCallbackDelegate.CB_CreateLinking);

  GamePot.createLinking(NCommon.LinkingType.XXXXX, (resultState, userInfo, error) => {
        switch (resultState)
      {
          case NCommon.ResultLinking.SUCCESS:
          // 账户关联成功
          break;
          case NCommon.ResultLinking.CANCELLED:
          // 取消账户关联
          break;
          case NCommon.ResultLinking.FAILED:
          // 账户关联失败
          break;
          default:
          break;
      }
  });
  ```

## 关联列表确认功能 <a href="#guan-lian-lie-biao-que-ren-gong-neng" id="guan-lian-lie-biao-que-ren-gong-neng"></a>

***

如要确认与账户关联的第三方账户列表，请使用下列代码。

```
List<NLinkingInfo> linkedList = GamePot.getLinkedList();

// 定义链接信息
public class NLinkingInfo
{
    public LinkingType provider { get; set; }  // google, facebook, naver, apple..
}
```

## 解除关联功能 <a href="#jie-chu-guan-lian-gong-neng" id="jie-chu-guan-lian-gong-neng"></a>

***

如要使用解除与第三方账户的关联功能，请使用下列代码。

&#x20;

* 方式1

  ```
  void GamePot.deleteLinking(NCommon.LinkingType.XXXXX);

  /// 账户关联解除成功
  public void onDeleteLinkingSuccess() {
  }

  /// 账户关联解除失败
  public void onDeleteLinkingFailure(NError error) {
      // 解除关联失败时
      // 请使用error.message显示错误消息。
  }
  ```

* 方式2

  ```
  void GamePot.deleteLinking(NCommon.LinkingType.XXXXX, GamePotCallbackDelegate.CB_Common);

  GamePot.deleteLinking(NCommon.LinkingType.XXXXX, (success, error) => {
      if(success)
      {
         // 账户关联解除成功
      }
     else
     {
          // 解除关联失败时
          // 请使用error.message显示错误消息。
      }
  });
  ```
