# 关联账号

当用户没有通过[Messneger登录按钮](/project/advanced-tool/api/account-link.md)，而是通过其他途径（例如邮件订阅确认）确认了要将Facebook账号和官网账号的绑定之后，可以通过这个接口通知Bothub，这样用户就完成了关联，可以在Messenger里收到关联成功的确认，并在今后的使用中享受绑定带来的便利。

## 开发指南

发送请求

您可以用任意一个已经启用的API Key（[怎样申请APIKey](https://docs.bothub.ai/project/untitled-2/api-jie-shao/kai-shi-shi-yong-api)）向Bothub发起请求，向一个手机号发送一条消息。这个请求的样例如下：

| **请求属性**  | **属性名**                        | **说明**                           |
| --------- | ------------------------------ | -------------------------------- |
| 地址        |                                | <https://api.bothub.ai/api>      |
| 请求方式      | POST                           |                                  |
| Header    | APIKEY                         | 您的API KEY                        |
| Form Data | request.method                 | 需要调用的api。此处设置为 account\_link     |
| Form Data | request.id                     | 由调用者生成的请求的唯一标识符                  |
| Form Data | recipient.id                   | 待关联的Facebook user id             |
| Form Data | account\_linking.username      | 待关联的官网账号(用户名)                    |
| Form Data | account\_linking.email         | 待关联的官网账号(邮箱)                     |
| Form Data | account\_linking.phone\_number | 待关联的官网账号(电话号码)                   |
| Form Data | account\_linking.status        | 取值为linked表示确认绑定，unlinked表示确认解除绑定 |
| Form Data | request.meta                   | 预留数据                             |

* 发送请求样例

```
{
    "recipient": {
        "id": "123456"
    },
    "timestamp": "1409291011",
    "account_linking": {
        "status": "linked",
        "username": "myaccount",
        "email": "mike@example.com",
        "phone_number": "18900001111"
    },
    "request": {
        "method": "account_link",
        "id" : "F4js0Za2",
        "meta": ""    
    }
}
```

#### 返回值 <a href="#fan-hui-zhi" id="fan-hui-zhi"></a>

| 返回值属性名         | 说明                        |
| -------------- | ------------------------- |
| request\_id    | 请求的唯一标识符，和请求的同名属性相同       |
| result         | 调用是否成功，true表示成功，false表示失败 |
| error\_code    | 错误码，0表示成功                 |
| error\_message | 错误信息                      |

* 成功返回样例

```
{
    'request_id': "F4js0Za2"
}
```

* 失败返回样例

```
{
    "error" : {
        "message": "Invalid Facebook user id",
        "type": "InvalidParamException",
        "code": 10000,
        "error_subcode": 1234567,
        "request_id": "F4js0Za2"
    }
}
```

#### 错误码 <a href="#cuo-wu-ma" id="cuo-wu-ma"></a>

| 错误码   | 说明                |
| ----- | ----------------- |
| 10000 | 无效的method参数       |
| 10005 | 无效的API KEY        |
| 13000 | 未指定fb\_user\_id   |
| 13001 | 未指定任何一种绑定方式       |
| 13002 | 绑定的fb\_user\_id无效 |
| 13003 | 指定的status无效       |

#### 调用说明 <a href="#tiao-yong-shuo-ming" id="tiao-yong-shuo-ming"></a>

* 接口支持用户名，邮箱，电话号码三种形式之一或多个与Facebook账号进行绑定。调用此api时，username, email和phone\_number至少要传一个。
* 此接口所指定的Facebook账号如果已经有绑定的账号了，那么会更新所绑定的官网账号。
* 此接口同样适用于用户先绑定邮箱，后续再绑定手机号这种情况。调用2次该接口，依序指定邮箱和手机号即可。
* 若调用此接口是为了解除绑定，则不需要传username，email或者phone\_number，而是解除该Facebook账号的所有关联官网账号。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bothub.gitbook.io/project/advanced-tool/api/account-binding.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
