← 返回目录
📁 API Reference › Ad Comments

删除评论

您可以使用本接口删除评论。

绑定以下两类认证身份,并且拥有评论管理权限的广告主可以删除自己的评论: - 自定义用户 (CUSTOMIZED_USER) - TikTok用户(TT_USER)

v1.2与v1.3版本对比

以下表格概括了 v1.2与v1.3接口的变化。 ``xtable |变化内容{30%}|v1.2{35%}|v1.3{35%}| |---|---|---| |接口路径| /v1.2/comment/delete/ | /v1.3/comment/delete/ | | 请求参数类型 |advertiser_id: number<br>comment_id: number <br>ad_id: number |advertiser_id: string <br>comment_id: string <br>ad_id: string | | 请求参数名称和类型|item_id: number|tiktok_item_id`: string|


## 请求

**地址**
https://business-api.tiktok.com/open_api/v1.3/comment/delete/

**方法** 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 |
| ad_id {必填} | string | 广告ID |
| tiktok_item_id {必填} | string |TikTok视频ID|
| comment_id {必填} | string | 您想要删除的评论ID |
| identity_type {必填} | string | 认证身份类型。枚举值:`CUSTOMIZED_USER` (自定义用户),`TT_USER` (TikTok用户)。关于认证身份的更多信息,请访问[认证身份](https://ads.tiktok.com/marketing_api/docs?id=1738958351620097)。|
| identity_id {必填} | string |认证身份ID |

示例

(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/comment/delete/";
    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 ad_id = AD_ID;
        String tiktok_item_id = TIKTOK_ITEM_ID;
        String comment_id = COMMENT_ID;
        String identity_type = IDENTITY_TYPE;
        String identity_id = IDENTITY_ID;

        // Args in JSON format
        String myArgs = String.format("{\"advertiser_id\": \"%s\", \"ad_id\": \"%s\", \"tiktok_item_id\": \"%s\", \"comment_id\": \"%s\", \"identity_type\": \"%s\", \"identity_id\": \"%s\"}",advertiser_id, ad_id, tiktok_item_id, comment_id, identity_type, identity_id);
        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/comment/delete/"


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
    ad_id = AD_ID
    tiktok_item_id = TIKTOK_ITEM_ID
    comment_id = COMMENT_ID
    identity_type = IDENTITY_TYPE
    identity_id = IDENTITY_ID

    # Args in JSON format
    my_args = "{\"advertiser_id\": \"%s\", \"ad_id\": \"%s\", \"tiktok_item_id\": \"%s\", \"comment_id\": \"%s\", \"identity_type\": \"%s\", \"identity_id\": \"%s\"}" % (advertiser_id, ad_id, tiktok_item_id, comment_id, identity_type, identity_id)
    print(post(my_args))
(/code)

(code PHP php)

$ACCESS_TOKEN = "xxx";
$PATH = "/open_api/v1.3/comment/delete/";

/**
 * 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;
$ad_id = AD_ID;
$tiktok_item_id = TIKTOK_ITEM_ID;
$comment_id = COMMENT_ID;
$identity_type = IDENTITY_TYPE;
$identity_id = IDENTITY_ID;

/* Args in JSON format */
$my_args = sprintf("{\"advertiser_id\": \"%s\", \"ad_id\": \"%s\", \"tiktok_item_id\": \"%s\", \"comment_id\": \"%s\", \"identity_type\": \"%s\", \"identity_id\": \"%s\"}", $advertiser_id, $ad_id, $tiktok_item_id, $comment_id, $identity_type, $identity_id);
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",
    "ad_id": "AD_ID",
    "tiktok_item_id": "TIKTOK_ITEM_ID",
    "comment_id": "COMMENT_ID",
    "identity_type": "IDENTITY_TYPE",
    "identity_id": "IDENTITY_ID"
}' \
https://business-api.tiktok.com/open_api/v1.3/comment/delete/
(/code)

返回

|Field|Data Type|Description|
|---|---|---|
|code |number|返回码,详见[附录-返回码](https://ads.tiktok.com/marketing_api/docs?id=1737172488964097)|
|message |string|返回信息,详见[附录-返回码](https://ads.tiktok.com/marketing_api/docs?id=1737172488964097)|
|data |object|返回数据  |
|request_id |string|请求的日志id,唯一标识一个请求 |

示例

(code Success-Response http)
HTTPS/1.1 200 OK
{
    "message": "OK",
    "code": 0,
    "data": {}
}
(/code)

内容来源:TikTok API for Business 官方文档 · 本地归档

在接这个接口时卡住了?
Stuck wiring this API into production? We build ad-delivery tooling on these platforms — campaign automation, reporting pipelines, error-handling and migration between API versions.
联系我们 · Talk to us 每日平台更新简报 →