# 处理 Google 登录回调

完成 Google OAuth 校验，并根据结果跳回站点。

GET `/api/account/google/callback`

- **认证** 公开，无需登录。
- **成功状态** `303`

## 请求参数

| 参数 | 类型 | 位置 | 必填 | 说明 |
| --- | --- | --- | --- | --- |
| `state` | string | `query` | 是 | 授权流程签发的状态值，需与浏览器状态 Cookie 配合使用。 |
| `code` | string | `query` | 否 | Google 授权成功时返回的授权码。 |

## 请求示例

**cURL**

```bash
curl -i -X GET 'https://social2api.com/api/account/google/callback?state=%3Coauth+state%3E&code=%3Cauthorization+code%3E'
```

**Python**

```python
from urllib.error import HTTPError
from urllib.request import Request, urlopen

request = Request(
    "https://social2api.com/api/account/google/callback?state=%3Coauth+state%3E&code=%3Cauthorization+code%3E",
    method="GET",
)
send = urlopen
try:
    with send(request) as response:
        print(response.status, response.read().decode("utf-8"))
except HTTPError as error:
    print(error.code, error.read().decode("utf-8"))
```

**JavaScript**

```javascript
const response = await fetch("/api/account/google/callback?state=%3Coauth+state%3E&code=%3Cauthorization+code%3E", {
  method: "GET",
});
console.log(response.status, await response.text());
```

## 响应

**303 · 示例响应**

无响应正文

**错误示例**

```json
{
  "error": "账户服务暂不可用，请稍后重试。"
}
```

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `Location` | URI reference | 结果为 google-success、google-email-code 或 google-error 的站内地址。 |
| `Set-Cookie` | header | 成功时建立会话，并在已匹配的回调中清除状态 Cookie。 |

## 错误状态

| HTTP | 原因与处理 |
| --- | --- |
| `405` | 请求方法不受支持。 |
| `500` | 账户服务暂时不可用。 |
| `503` | Google 登录尚未配置。 |

## 使用细节

-   此接口只用于 Google 发起的浏览器回调。OAuth 失败通常也通过 303 跳转显示。

## 同组接口

-   [GET 读取登录会话](<https://social2api.com/docs/api/account-session/>)
-   [POST 注册账号](<https://social2api.com/docs/api/account-register/>)
-   [POST 登录账号](<https://social2api.com/docs/api/account-login/>)
-   [POST 退出登录](<https://social2api.com/docs/api/account-logout/>)
-   [PATCH 更新账号显示名](<https://social2api.com/docs/api/account-profile/>)
-   [PATCH 更新账号语言](<https://social2api.com/docs/api/account-preferences/>)
-   [POST 设置或修改密码](<https://social2api.com/docs/api/account-password/>)
-   [POST 删除当前账号](<https://social2api.com/docs/api/account-delete/>)
-   [POST 发送邮箱验证码](<https://social2api.com/docs/api/account-otp-request/>)
-   [POST 验证邮箱验证码](<https://social2api.com/docs/api/account-otp-verify/>)
-   [GET 开始 Google 登录](<https://social2api.com/docs/api/account-google/>)

规范页面：<https://social2api.com/docs/api/account-google-callback/>
