[comment]: # translation:outdated

[comment]: # ({d632e1b8-d632e1b8})
# 获取

[comment]: # ({/d632e1b8-d632e1b8})

[comment]: # ({980bb7e6-980bb7e6})
### 描述

`integer/array token.get(object parameters)`

此方法允许根据给定的参数获取令牌。

::: noteclassic
只允许 *Super admin(超级管理员)* 用户可以查看其他用户的令牌。
:::

[comment]: # ({/980bb7e6-980bb7e6})

[comment]: # ({11ccf164-cc094e72})
### 参数

`(object)` 定义期望输出的参数。

此方法支持以下参数。

|参数|[类型](/manual/api/reference_commentary#数据类型)|描述|
|---------|---------------------------------------------------|-----------|
|tokenids|string/array|仅返回给定ID的令牌。|
|userids|string/array|仅返回为给定用户创建的令牌。|
|token|string|仅返回为给定*身份验证令牌*创建的令牌。|
|valid\_at|timestamp|仅返回在给定的日期和时间内是有效(未过期)的令牌。|
|expired\_at|timestamp|仅返回在给定的日期和时间内是过期(无效)的令牌。|
|sortfield|string/array|按给定的属性对结果进行排序。<br><br>可用值:`tokenid`，`name`，`lastaccess`，`status`，`expires_at`和`created_at`。|
|countOutput|boolean|这些参数对所有的 `get` 方法是通用的，详情请参阅 [参考说明](/manual/api/reference_commentary#通用get方法参数) 。|
|excludeSearch|boolean|^|
|filter|object|^|
|limit|integer|^|
|output|query|^|
|preservekeys|boolean|^|
|search|object|^|
|searchByAny|boolean|^|
|searchWildcardsEnabled|boolean|^|
|sortorder|string/array|^|
|startSearch|boolean|^|

[comment]: # ({/11ccf164-cc094e72})

[comment]: # ({7223bab1-7223bab1})
### 返回值

(integer/array) 返回其中之一：

-   对象数组；

-   如果使用了 countOutput 参数，则检索到对象的数量。

[comment]: # ({/7223bab1-7223bab1})

[comment]: # ({b41637d2-b41637d2})
### 示例

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({e2f1b2d9-66760f5f})
#### 检索令牌

检索 ID 为“2”的令牌的所有数据。

请求：

```json
{
    "jsonrpc": "2.0",
    "method": "token.get",
    "params": {
        "output": "extend",
        "tokenids": "2"
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

响应：

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "tokenid": "1",
            "name": "The Token",
            "description": "",
            "userid": "1",
            "lastaccess": "0",
            "status": "0",
            "expires_at": "1609406220",
            "created_at": "1611239454",
            "creator_userid": "1"
        }
    ],
    "id": 1
}
```

[comment]: # ({/e2f1b2d9-66760f5f})

[comment]: # ({5cf2ab45-5cf2ab45})
### 来源

*ui/include/classes/api/services/CToken.php* 中的 CToken::get()。

[comment]: # ({/5cf2ab45-5cf2ab45})
