> ## Documentation Index
> Fetch the complete documentation index at: https://help.dingtalk.io/llms.txt
> Use this file to discover all available pages before exploring further.

# サイレントログインコードを使用してユーザー情報を取得する

> ミニプログラムやマイクロアプリのサイレントログイン認可コードでユーザー情報を取得します

## リクエスト

| **基本情報**      |                                                                                                          |
| ------------- | -------------------------------------------------------------------------------------------------------- |
| HTTP URL      | [https://api.dingtalk.io/topapi/v2/user/getuserinfo](https://api.dingtalk.io/topapi/v2/user/getuserinfo) |
| HTTP Method   | POST                                                                                                     |
| サポートされるアプリタイプ | appType-社内アプリ appType-サードパーティ社内アプリ                                                                       |
| 権限要件          | permission-qyapi\_base-企業 API を呼び出す際に必要な基本権限                                                             |

### クエリパラメータ

| 名前            | タイプ    | 必須 | 例        | 説明                                                                                                                                                                              |
| ------------- | ------ | -- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| access\_token | String | はい | 6ed1bxxx | この API を呼び出すアプリ認証情報です。   - 社内アプリの場合、[社内アプリの access\_token 取得](/ja/open/development/obtain-orgapp-token) API から取得します。 - サードパーティ社内アプリの場合、サードパーティ企業の access\_token 取得 API から取得します。 |

### リクエストボディ

| 名前   | タイプ    | 必須 | 例                     | 説明                                                                                                                            |
| ---- | ------ | -- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| code | String | はい | bab02f63c1e030fbbxxxx | サイレントログイン認可コード。取得方法は以下をご参照ください。   - ミニプログラムのサイレントログイン認可コード - マイクロアプリのサイレントログイン認可コード   **説明**  この認可コードは 5 分間のみ有効で、一度しか使用できません。 |

### リクエスト例

```curl theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://api.dingtalk.io/topapi/v2/user/getuserinfo" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'access_token=417124xxxx2a3c270d5' \
-d 'code=123456'
```

Java

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
DingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/v2/user/getuserinfo");
OapiV2UserGetuserinfoRequest req = new OapiV2UserGetuserinfoRequest();
req.setCode("bab02f63c1e030fbbxxxx");
OapiV2UserGetuserinfoResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
```

Python

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
# -*- coding: utf-8 -*-
import dingtalk.api

req=dingtalk.api.OapiV2UserGetuserinfoRequest("https://api.dingtalk.io/topapi/v2/user/getuserinfo")

req.code="123456"
try:
  resp= req.getResponse(access_token)
  print(resp)
except Exception,e:
  print(e)
```

PHP

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
include "TopSdk.php";
date_default_timezone_set('Asia/Shanghai');

$c = new DingTalkClient(DingTalkConstant::$CALL_TYPE_OAPI, DingTalkConstant::$METHOD_POST , DingTalkConstant::$FORMAT_JSON);
$req = new OapiV2UserGetuserinfoRequest;
$req->setCode("123456");
$resp = $c->execute($req, $access_token, "https://api.dingtalk.io/topapi/v2/user/getuserinfo");
```

Node.js

```javascript theme={"theme":{"light":"github-light","dark":"github-dark"}}
let { Config, OapiV2UserGetuserinfoParams, OapiV2UserGetuserinfoRequest } = require('./client.js');
let Client = require('./client.js').default
async function test() {
  const config = new Config()
  config.serverUrl = 'https://api.dingtalk.io/topapi/v2/user/getuserinfo'
  config.session = 'access_token'
  const params = new OapiV2UserGetuserinfoParams();
  params.code = 'bab02f63c1e030fbbxxxx'

  const request = new OapiV2UserGetuserinfoRequest()
  request.params = params
  const client = new Client(config)
  try {
    const res = await client.oapiV2UserGetuserinfo(request)
    console.log(res.body)
  } catch (err) {
    console.log(err)
  }
}
test()
```

C#

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
IDingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/v2/user/getuserinfo");
OapiV2UserGetuserinfoRequest req = new OapiV2UserGetuserinfoRequest();
req.Code = "123456";
OapiV2UserGetuserinfoResponse rsp = client.Execute(req, access_token);
Console.WriteLine(rsp.Body);
```

## レスポンス

### レスポンスボディ

| 名前                  | タイプ                   | 例              | 説明                                                                    |
| ------------------- | --------------------- | -------------- | --------------------------------------------------------------------- |
| request\_id         | String                | e8krly4vyiln   | リクエスト ID。                                                             |
| errcode             | Number                | 0              | リターンコード\*\*。\*\*                                                      |
| errmsg              | String                | ok             | リターンコードに対するテキストの説明内容。                                                 |
| result              | UserGetByCodeResponse |                | 戻り結果。                                                                 |
| userid              | String                | user456        | ユーザーの userId。                                                         |
| device\_id          | String                | 12drtfxxxxx    | デバイス ID。                                                              |
| sys                 | Boolean               | true           | 管理者かどうか。   - **true**：はい - **false**：いいえ                              |
| sys\_level          | Number                | 1              | レベル。   - **1**：スーパー管理者 - **2**：サブ管理者 - **100**：ボス - **0**：その他（一般社員など） |
| associated\_unionid | String                | N2o5U3axxxx    | ユーザーが関連付けられた unionId。                                                 |
| unionid             | String                | gliiW002zUxxxx | ユーザーの unionId。                                                        |
| name                | String                | 山田太郎           | ユーザー名。                                                                |

### レスポンスボディ例

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "errcode": 0, 
  "result": {
    "associated_unionid": "N2o5U3axxxx", 
    "unionid": "gliiW0piiii02zBUjUxxxx", 
    "device_id": "12drtfxxxxx", 
    "sys_level": 1, 
    "name": "山田太郎", 
    "sys": true, 
    "userid": "userid123"
  }, 
  "errmsg": "ok"
}
```

### エラーコード

この API の呼び出しでエラーが発生した場合は、エラーメッセージをもとに [グローバルエラーコード](/ja/open/development/server-api-error-codes-1) ドキュメントで解決策をご確認ください。
