Request
| Basic information | |
|---|---|
| HTTP URL | https://api.dingtalk.io/v1.0/sns/getuserinfo_bycode |
| HTTP Method | POST |
| Supported app types | appType-Internal appappType-Third-party enterprise app |
| Permissions | permission-open_app_api_base-Basic permission to obtain the user access credential for DingTalk open APIs |
Query parameters
| Name | Type | Required | Description |
|---|---|---|---|
| accessKey | String | Yes | The AppId of the app. |
| timestamp | String | Yes | The current timestamp, in milliseconds. |
| signature | String | Yes | The signature value calculated using the HmacSHA256 algorithm, with timestamp+“\n”+AppSecret as the signature string and AppSecret as the signing key. |
Request body
| Name | Type | Required | Description |
|---|---|---|---|
| tmp_auth_code | String | Yes | The 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://api.dingtalk.io/v1.0/sns/getuserinfo_bycode" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'tmp_auth_code=abcdef'
DefaultDingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/v1.0/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");
import dingtalk.api
req = dingtalk.api.OapiSnsGetuserinfoBycodeRequest("https://api.dingtalk.io/v1.0/sns/getuserinfo_bycode")
req.tmp_auth_code = "abcdef"
try:
resp = req.getResponse("yourAppId", "yourAppSecret")
print(resp)
except Exception as e:
print(e)
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://api.dingtalk.io/v1.0/sns/getuserinfo_bycode");
IDingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/v1.0/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 code | Description |
|---|---|
| 853002 | The timestamp parameter is invalid. The value differs from the current time on the DingTalk server by more than 1 minute. |
| 853001 | The timestamp parameter format is incorrect. It must be the current time in milliseconds. |
| 853003 | The accessKey parameter is invalid. It must be an appId that exists on the DingTalk Open Platform. |
| 853004 | The signature parameter is incorrect and does not match the signature calculated by the DingTalk server. Note that this parameter must be urlEncoded when passed. |