← 返回 API 列表 ← 项目门户

批量修改投放项目下素材状态

关键信息详情
文档 ID1854930119140363
标签 ID7
原始文档[https://open.oceanengine.com/labels/7/docs/1854930119140363](https://open.oceanengine.com/labels/7/docs/1854930119140363)
接口标识oc_project.material.status.update
💡批量修改投放项目下素材的启用或暂停状态,可同时更新1 - 100个素材状态。 批量修改投放项目下素材状态
POST https://api.oceanengine.com/open_api/v3.0/oc_project/material/status/update/ 🔍 可视化调试 📦 SDK下载

接口说明

批量修改投放项目下素材的启用或暂停状态,可同时更新1 - 100个素材状态。

批量修改投放项目下素材状态

请求地址

https://api.oceanengine.com/open_api/v3.0/oc_project/material/status/update/可视化调试SDK下载

请求方法

POST

Header

字段 类型 必填 描述
Access-Token string 必填 授权access_token,可以通过【获取Access token】接口获取
Content-Type string 必填 请求消息类型
允许值: application/json

请求参数

字段 类型 必填 描述
advertiser_id number 必填 客户id
project_id number 必填 项目id
data(object[],必填) — 批量更新项目素材启用状态,list长度限制1~100 | 字段 | 类型 | 必填 | 描述 | | --- | --- | --- | --- | | `material_id` | number | 必填 | 素材id | | `opt_status` | string | 必填 | 可选值:
- `DISABLE` 暂停
- `ENABLE` 启用 |

请求示例

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/v3.0/uni_project/material/status/update/"


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", "api.oceanengine.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
    project_id = PROJECT_ID
    material_id = MATERIAL_ID
    opt_status = OPT_STATUS

    # Args in JSON format
    my_args = "{\"advertiser_id\": \"%s\", \"project_id\": \"%s\", \"data\": [{\"material_id\": \"%s\", \"opt_status\": \"%s\"}]}" % (advertiser_id, project_id, material_id, opt_status)
    print(post(my_args))

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/v3.0/uni_project/material/status/update/";
    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", "api.oceanengine.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 {
        Long advertiser_id = ADVERTISER_ID;
        Long project_id = PROJECT_ID;
        Long material_id = MATERIAL_ID;
        String opt_status = OPT_STATUS;

        // Args in JSON format
        String myArgs = String.format("{\"advertiser_id\": \"%s\", \"project_id\": \"%s\", \"data\": [{\"material_id\": \"%s\", \"opt_status\": \"%s\"}]}",advertiser_id, project_id, material_id, opt_status);
        System.out.println(post(myArgs));
    }
}

php


$ACCESS_TOKEN = "xxx";
$PATH = "/open_api/v3.0/uni_project/material/status/update/";

/**
 * Build request URL
 * @param $path : Request path
 * @return string
 */
function build_url($path)
{
    return "https://api.oceanengine.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;
$project_id = PROJECT_ID;
$material_id = MATERIAL_ID;
$opt_status = OPT_STATUS;

/* Args in JSON format */
$my_args = sprintf("{\"advertiser_id\": \"%s\", \"project_id\": \"%s\", \"data\": [{\"material_id\": \"%s\", \"opt_status\": \"%s\"}]}", $advertiser_id, $project_id, $material_id, $opt_status);
echo post($my_args);

curl

curl -H "Access-Token:xxx" -H "Content-Type:application/json" -X POST \
-d '{
    "advertiser_id": "ADVERTISER_ID",
    "project_id": "PROJECT_ID",
    "data": [
        {
            "material_id": "MATERIAL_ID",
            "opt_status": "OPT_STATUS"
        }
    ]
}' \
https://api.oceanengine.com/open_api/v3.0/uni_project/material/status/update/

应答字段

字段 类型 必填 描述
code number 否 返回码,详见 【附录-返回码】
message string 否 返回信息,详见 【附录-返回码】
data(json,否) — json返回值 | 字段 | 类型 | 必填 | 描述 | | --- | --- | --- | --- | | `project_id` | number | 否 | 项目id | | `material_ids` | number[] | 否 | 更新成功的素材ID集合 |
errors(object[],否) — 更新失败的素材列表 | 字段 | 类型 | 必填 | 描述 | | --- | --- | --- | --- | | `material_id` | number | 否 | 素材ID | | `message` | string | 否 | 失败原因 |
字段 类型 必填 描述
request_id string 否 请求日志id

应答示例

HTTPS/1.1 200 OK
{
    "message": "OK",
    "code": 0,
    "data": {}
}

业务错误码

仅披露当前接口高频的参数校验报错,更多常见报错详见「返回码」文档

在接这个接口时卡住了?
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 每日平台更新简报 →