创建认证身份
您可以使用本接口创建自定义用户 (CUSTOMIZED_USER)类型的认证身份。
v1.2与v1.3版本对比
以下表格概括了 v1.2与v1.3接口的变化。
``xtable
|变化内容{30%}|v1.2{35%}|v1.3{35%}|
|---|---|---|
|接口路径| /v1.2/identity/create/| /v1.3/identity/create/|
|请求参数名称|avatar_icon_web_uri|image_uri|
|请求参数类型|advertiser_id: number | advertiser_id`: string |
## 请求
**地址**
https://business-api.tiktok.com/open_api/v1.3/identity/create/
**方法** POST
**Header**
``` xtable
|字段|类型|描述|
|---|---|---|
|Access-Token {必填}|string|授权访问令牌。可以通过[获取访问令牌](https://ads.tiktok.com/marketing_api/docs?id=1738373164380162)接口获取。|
|Content-Type {必填}|string|请求信息类型。<br>允许格式:`application/json`。|
参数
|字段|类型|描述|
|---|---|---|
| advertiser_id {必填} | string |广告主ID。|
| display_name {必填} | string |显示名称。<br><br>最大长度为100个字符。|
| image_uri | string |认证身份的头像图片的ID。<br><br>头像图片的长宽比必须为1:1。<br><br>若想获取头像图片的ID,您可使用[/file/image/ad/upload/](https://ads.tiktok.com/marketing_api/docs?id=1739067433456642)上传该图片。<br><br>若未传入本字段,将使用默认图片作为头像。 |
示例
(code Java java)
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import okhttp3.*;
import org.apache.http.client.utils.URIBuilder;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class Demo {
private static final String ACCESS_TOKEN = "xxx";
private static final String PATH = "/open_api/v1.3/identity/create/";
private static final ObjectMapper mapper = new ObjectMapper();
/**
* Build request URL
*
* @param path Request path
* @return Request URL
*/
private static String buildUrl(String path) throws URISyntaxException {
URI uri = new URI("https", "business-api.tiktok.com", path, "", "");
return uri.toString();
}
/**
* Send POST request
*
* @param jsonStr Args in JSON format
* @return Response in JSON format
*/
private static String post(String jsonStr) throws IOException, URISyntaxException {
OkHttpClient client = new OkHttpClient().newBuilder().build();
String url = buildUrl(PATH);
RequestBody body = RequestBody.create(MediaType.parse("application/json"), jsonStr);
Request request = new Request.Builder()
.url(url)
.method("POST", body)
.addHeader("Content-Type", "application/json")
.addHeader("Access-Token", ACCESS_TOKEN)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
public static void main(String[] args) throws IOException, URISyntaxException {
String advertiser_id = ADVERTISER_ID;
String image_uri = IMAGE_URI;
String display_name = DISPLAY_NAME;
// Args in JSON format
String myArgs = String.format("{\"advertiser_id\": \"%s\", \"image_uri\": \"%s\", \"display_name\": \"%s\"}",advertiser_id, image_uri, display_name);
System.out.println(post(myArgs));
}
}
(/code)
(code Python python)
# coding=utf-8
import json
import requests
from six import string_types
from six.moves.urllib.parse import urlencode, urlunparse # noqa
ACCESS_TOKEN = "xxx"
PATH = "/open_api/v1.3/identity/create/"
def build_url(path, query=""):
# type: (str, str) -> str
"""
Build request URL
:param path: Request path
:param query: Querystring
:return: Request URL
"""
scheme, netloc = "https", "business-api.tiktok.com"
return urlunparse((scheme, netloc, path, "", query, ""))
def post(json_str):
# type: (str) -> dict
"""
Send POST request
:param json_str: Args in JSON format
:return: Response in JSON format
"""
url = build_url(PATH)
args = json.loads(json_str)
headers = {
"Access-Token": ACCESS_TOKEN,
"Content-Type": "application/json",
}
rsp = requests.post(url, headers=headers, json=args)
return rsp.json()
if __name__ == '__main__':
advertiser_id = ADVERTISER_ID
image_uri = IMAGE_URI
display_name = DISPLAY_NAME
# Args in JSON format
my_args = "{\"advertiser_id\": \"%s\", \"image_uri\": \"%s\", \"display_name\": \"%s\"}" % (advertiser_id, image_uri, display_name)
print(post(my_args))
(/code)
(code PHP php)
$ACCESS_TOKEN = "xxx";
$PATH = "/open_api/v1.3/identity/create/";
/**
* Build request URL
* @param $path : Request path
* @return string
*/
function build_url($path)
{
return "https://business-api.tiktok.com" . $path;
}
/**
* Send POST request
* @param $json_str : Args in JSON format
* @return bool|string : Response in JSON format
*/
function post($json_str)
{
global $ACCESS_TOKEN, $PATH;
$curl = curl_init();
$url = build_url($PATH);
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $json_str,
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"Access-Token: " . $ACCESS_TOKEN,
),
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
$advertiser_id = ADVERTISER_ID;
$image_uri = IMAGE_URI;
$display_name = DISPLAY_NAME;
/* Args in JSON format */
$my_args = sprintf("{\"advertiser_id\": \"%s\", \"image_uri\": \"%s\", \"display_name\": \"%s\"}", $advertiser_id, $image_uri, $display_name);
echo post($my_args);
(/code)
(code curl http)
curl -H "Access-Token:xxx" -H "Content-Type:application/json" -X POST \
-d '{
"advertiser_id": "ADVERTISER_ID",
"image_uri": "IMAGE_URI",
"display_name": "DISPLAY_NAME"
}' \
https://business-api.tiktok.com/open_api/v1.3/identity/create/
(/code)
返回
|字段|类型|描述|
|---|---|---|
|code |number|返回码,详见[附录-返回码](https://ads.tiktok.com/marketing_api/docs?id=1737172488964097)。|
|message |string|返回信息,详见[附录-返回码](https://ads.tiktok.com/marketing_api/docs?id=1737172488964097)。|
|data|object|返回数据。|
#|identity_id|string|认证身份 ID。|
|request_id |string|请求的日志 ID,唯一标识一个请求。|
示例
(code Success-Response http)
HTTPS/1.1 200 OK
{
"code": 0,
"message": "OK",
"request_id": "LOG_ID",
"data": {
"identity_id": "IDENTITY_ID"
}
}
(/code)