Skip to main content
Call this API to get basic user information through the silent login authorization code.

Request

Basic information
HTTP URLhttps://oapi.dingtalk.io/sns/getuserinfo_bycode
HTTP MethodPOST
Supported app typesappType-Internal appappType-Third-party enterprise app
Permissionspermission-open_app_api_base-Basic permission to obtain the user access credential for DingTalk open APIs

Query parameters

NameTypeRequiredDescription
accessKeyStringYesThe AppId of the app.
timestampStringYesThe current timestamp, in milliseconds.
signatureStringYesThe signature value calculated using the HmacSHA256 algorithm, with timestamp+“\n”+AppSecret as the signature string and AppSecret as the signing key.

Request body

NameTypeRequiredDescription
tmp_auth_codeStringYesThe silent login authorization code granted by the user to the DingTalk open app. Obtain it by calling the JSAPI dd.getAuthCode. See silent login authorization code for details.

Request example

curl -X POST "https://oapi.dingtalk.io/sns/getuserinfo_bycode" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'tmp_auth_code=abcdef'
Java
DefaultDingTalkClient  client = new DefaultDingTalkClient("https://oapi.dingtalk.io/sns/getuserinfo_bycode");
// If this class does not exist in your SDK, download the latest SDK
OapiSnsGetuserinfoBycodeRequest req = new OapiSnsGetuserinfoBycodeRequest();
req.setTmpAuthCode("4a2c5695b78738d495f47b5fee9160cd");
OapiSnsGetuserinfoBycodeResponse response = client.execute(req,"yourAppId","yourAppSecret");
Python
import dingtalk.api

req = dingtalk.api.OapiSnsGetuserinfoBycodeRequest("https://oapi.dingtalk.io/sns/getuserinfo_bycode")
req.tmp_auth_code = "abcdef"
try:
  resp = req.getResponse("yourAppId", "yourAppSecret")
  print(resp)
except Exception as e:
  print(e)
PHP
include "TopSdk.php";
date_default_timezone_set('Asia/Shanghai');

$c = new DingTalkClient(DingTalkConstant::$CALL_TYPE_OAPI, DingTalkConstant::$METHOD_POST , DingTalkConstant::$FORMAT_JSON);
$req = new OapiSnsGetuserinfoBycodeRequest;
$req->setTmpAuthCode("abcdef");
$resp = $c->execute($req,"yourAppId","yourAppSecret", "https://oapi.dingtalk.io/sns/getuserinfo_bycode");
C#
IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.io/sns/getuserinfo_bycode");
OapiSnsGetuserinfoBycodeRequest req = new OapiSnsGetuserinfoBycodeRequest();
req.TmpAuthCode = "abcdef";
OapiSnsGetuserinfoBycodeResponse rsp = client.Execute(req, "yourAppId", "yourAppSecret");
Console.WriteLine(rsp.Body);

Response

Response body example

{
  "errcode": 0,
  "errmsg": "ok",
  "user_info": {
    "nick": "John",
    "unionid": "Wzh9KbyaCZxxx",
    "openid": "EtiiaAu3Yf9Ruxxx",
    "main_org_auth_high_level": true
  }
}

Error codes

If an error occurs when calling this API, refer to the global error codes document to find a solution based on the error message.
Error codeDescription
853002The timestamp parameter is invalid. The value differs from the current time on the DingTalk server by more than 1 minute.
853001The timestamp parameter format is incorrect. It must be the current time in milliseconds.
853003The accessKey parameter is invalid. It must be an appId that exists on the DingTalk Open Platform.
853004The signature parameter is incorrect and does not match the signature calculated by the DingTalk server. Note that this parameter must be urlEncoded when passed.