### Simple GET Request Example Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/api-reference/03-CommonReqApi.md Demonstrates how to make a simple GET request using the commonReq method. Ensure you have set up the ApiClient and added necessary headers like 'Access-Token'. ```java import com.bytedance.ads.api.CommonReqApi; import com.bytedance.ads.model.CommonResponse; import com.bytedance.ads.Pair; import java.util.Arrays; import java.util.List; CommonReqApi api = new CommonReqApi(); ApiClient client = api.getApiClient(); client.addDefaultHeader("Access-Token", "your_access_token"); List queryParams = Arrays.asList( new Pair("account_ids", "123456") ); try { CommonResponse response = api.commonReq( "GET", "/open_api/v3.0/account/fund/get/", null, // contentType 不需要 queryParams, // 查询参数 null, // formParams null // requestBody ); System.out.println("响应码: " + response.getCode()); System.out.println("响应消息: " + response.getMessage()); System.out.println("响应数据: " + response.getData()); } catch (ApiException e) { System.err.println("API 调用失败: " + e.getMessage()); } ``` -------------------------------- ### Get Ad Information (Java) Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/endpoints.md This example shows how to get ad information. It can be called via CommonReqApi or a dedicated API class. ```java import com.bytedance.ads.api.AdGetV2Api; AdGetV2Api api = new AdGetV2Api(); // 通过 CommonReqApi 调用或专用 API 类 ``` -------------------------------- ### JSON POST Request Example Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/api-reference/03-CommonReqApi.md This example shows how to make a JSON POST request to create a campaign. ```APIDOC ## POST /open_api/v3.0/campaign/create/ ### Description Creates a new campaign with the provided details. ### Method POST ### Endpoint /open_api/v3.0/campaign/create/ ### Parameters #### Request Body - **account_id** (integer) - Required - The ID of the account. - **name** (string) - Required - The name of the new campaign. - **budget** (integer) - Required - The budget for the campaign. ### Request Example ```json { "account_id": 123456, "name": "New Campaign", "budget": 5000 } ``` ### Response #### Success Response (200) - **code** (integer) - The response code. - **data** (object) - The data returned from the API, indicating the creation result. #### Response Example ```json { "code": 200, "data": { "campaign_id": "123456789" } } ``` ``` -------------------------------- ### GET Request Example - Simple GET Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/api-reference/03-CommonReqApi.md Demonstrates how to make a simple GET request using the `commonReq` method with query parameters. ```java import com.bytedance.ads.api.CommonReqApi; import com.bytedance.ads.model.CommonResponse; import com.bytedance.ads.Pair; import java.util.Arrays; import java.util.List; CommonReqApi api = new CommonReqApi(); ApiClient client = api.getApiClient(); client.addDefaultHeader("Access-Token", "your_access_token"); List queryParams = Arrays.asList( new Pair("account_ids", "123456") ); try { CommonResponse response = api.commonReq( "GET", "/open_api/v3.0/account/fund/get/", null, // contentType is not needed for GET queryParams, // query parameters null, // formParams null // requestBody ); System.out.println("Response Code: " + response.getCode()); System.out.println("Response Message: " + response.getMessage()); System.out.println("Response Data: " + response.getData()); } catch (ApiException e) { System.err.println("API Call Failed: " + e.getMessage()); } ``` -------------------------------- ### POST Request with Query Parameters Example Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/api-reference/03-CommonReqApi.md This example shows how to make a POST request that includes query parameters. ```APIDOC ## POST /open_api/v3.0/some/endpoint/ ### Description This endpoint accepts POST requests with both query parameters and a JSON request body. ### Method POST ### Endpoint /open_api/v3.0/some/endpoint/ ### Parameters #### Query Parameters - **account_id** (string) - Required - The ID of the account. #### Request Body - **data** (string) - Required - Some data payload. ### Request Example ```json { "account_id": "123456", "data": "some_data" } ``` ### Response #### Success Response (200) - **code** (integer) - The response code. - **data** (object) - The data returned from the API. #### Response Example ```json { "code": 200, "data": { "message": "Request processed successfully" } } ``` ``` -------------------------------- ### Asynchronous Common Request Example Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/api-reference/03-CommonReqApi.md Demonstrates how to use the `commonReqAsync` method to make an asynchronous GET request. Includes setting up the API client, adding headers, defining query parameters, and implementing the success and failure callbacks. ```java import com.bytedance.ads.ApiCallback; import java.util.List; import java.util.Map; CommonReqApi api = new CommonReqApi(); ApiClient client = api.getApiClient(); client.addDefaultHeader("Access-Token", "your_access_token"); List queryParams = Arrays.asList( new Pair("account_ids", "123456") ); okhttp3.Call call = api.commonReqAsync( "GET", "/open_api/v3.0/account/fund/get/", null, queryParams, null, null, new ApiCallback() { @Override public void onSuccess(CommonResponse response, int statusCode, Map> headers) { System.out.println("请求成功: " + response.getCode()); System.out.println("响应数据: " + response.getData()); } @Override public void onFailure(ApiException e, int statusCode, Map> headers) { System.err.println("请求失败: " + e.getMessage()); } } ); // 可选:取消请求 // call.cancel(); ``` -------------------------------- ### Complete Helper Class Example Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/api-reference/05-HelperClasses.md This example demonstrates the integrated usage of various helper classes, including Pair, ApiClient, and CommonReqApi, for making both synchronous and asynchronous API requests. ```APIDOC ## Helper Class Usage Example ### Description Demonstrates how to use helper classes like `Pair`, `ApiClient`, and `CommonReqApi` to perform API operations, including setting up the client, making synchronous requests with `commonReqWithHttpInfo`, and handling asynchronous requests with `commonReqAsync`. ### Steps: 1. **Create Pair Parameters**: Instantiate `Pair` objects for query parameters. 2. **Configure API Client**: Initialize `ApiClient`, set the base path, and add default headers like `Access-Token`. 3. **Execute Synchronous Request**: Use `CommonReqApi` to make a synchronous call and retrieve the `ApiResponse`. 4. **Process Response**: Extract status code, headers, and data from the `ApiResponse`. 5. **Asynchronous Request**: Initiate an asynchronous request using `commonReqAsync` and provide a callback for success or failure. ### Code Example ```java import com.bytedance.ads.*; import com.bytedance.ads.model.CommonResponse; import java.util.Arrays; import java.util.List; import java.util.Map; public class HelperClassExample { public static void main(String[] args) throws ApiException { // 1. 创建 Pair 参数 List params = Arrays.asList( new Pair("account_ids", "123456"), new Pair("account_type", "ACCOUNT") ); // 2. 配置 API 客户端 ApiClient apiClient = new ApiClient(); apiClient.setBasePath("https://api.oceanengine.com"); apiClient.addDefaultHeader("Access-Token", "token"); // 3. 执行同步请求,获取 ApiResponse CommonReqApi api = new CommonReqApi(apiClient); ApiResponse response = api.commonReqWithHttpInfo( "GET", "/open_api/v3.0/account/fund/get/", null, params, null, null ); // 4. 处理响应 int statusCode = response.getStatusCode(); Map> headers = response.getHeaders(); CommonResponse data = response.getData(); System.out.println("Status: " + statusCode); System.out.println("Response: " + data.getCode()); // 5. 异步请求示例 api.commonReqAsync( "GET", "/open_api/v3.0/account/fund/get/", null, params, null, null, new ApiCallback() { @Override public void onSuccess(CommonResponse result, int code, Map> headers) { System.out.println("异步请求成功: " + result.getCode()); } @Override public void onFailure(ApiException e, int code, Map> headers) { System.err.println("异步请求失败: " + e.getMessage()); } } ); } } ``` ``` -------------------------------- ### Full Helper Class Usage Example Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/api-reference/05-HelperClasses.md Demonstrates creating Pair parameters, configuring the API client with a base path and access token, executing synchronous requests, and handling the response. Also includes an example of an asynchronous request. ```java import com.bytedance.ads.*; import com.bytedance.ads.model.CommonResponse; import java.util.Arrays; import java.util.List; import java.util.Map; public class HelperClassExample { public static void main(String[] args) throws ApiException { // 1. 创建 Pair 参数 List params = Arrays.asList( new Pair("account_ids", "123456"), new Pair("account_type", "ACCOUNT") ); // 2. 配置 API 客户端 ApiClient apiClient = new ApiClient(); apiClient.setBasePath("https://api.oceanengine.com"); apiClient.addDefaultHeader("Access-Token", "token"); // 3. 执行同步请求,获取 ApiResponse CommonReqApi api = new CommonReqApi(apiClient); ApiResponse response = api.commonReqWithHttpInfo( "GET", "/open_api/v3.0/account/fund/get/", null, params, null, null ); // 4. 处理响应 int statusCode = response.getStatusCode(); Map> headers = response.getHeaders(); CommonResponse data = response.getData(); System.out.println("Status: " + statusCode); System.out.println("Response: " + data.getCode()); // 5. 异步请求示例 api.commonReqAsync( "GET", "/open_api/v3.0/account/fund/get/", null, params, null, null, new ApiCallback() { @Override public void onSuccess(CommonResponse result, int code, Map> headers) { System.out.println("异步请求成功: " + result.getCode()); } @Override public void onFailure(ApiException e, int code, Map> headers) { System.err.println("异步请求失败: " + e.getMessage()); } } ); } } ``` -------------------------------- ### SDK Navigation by Reading Order Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/README.md Follow this sequence for initial setup and in-depth understanding of the SDK. ```text 新手入门 → 快速开始.md ↓ 配置和认证 → authentication.md + configuration.md ↓ 开始调用 → api-reference/01-ApiClient.md + api-reference/03-CommonReqApi.md ↓ 错误处理 → errors.md ↓ 高级主题 → api-reference/02-ApiException.md + api-reference/04-Configuration.md + api-reference/05-HelperClasses.md ↓ 参考查询 → 目录和概览.md + types.md + endpoints.md ``` -------------------------------- ### AccountFundGetV30Api Example Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/endpoints.md Demonstrates how to create an API instance, configure the client, and call the `openApiV30AccountFundGetGet` method for retrieving account funds. ```APIDOC ## GET /open_api/v3.0/account/fund/get/ ### Description Retrieves account fund information. This is an example of a GET request using the v3.0 API. ### Method GET ### Endpoint /open_api/v3.0/account/fund/get/ ### Parameters #### Query Parameters - **account_ids** (List) - Required - The IDs of the accounts to retrieve fund information for. - **account_type** (String) - Optional - The type of account. ### Request Example ```java import com.bytedance.ads.api.AccountFundGetV30Api; import com.bytedance.ads.ApiClient; import com.bytedance.ads.ApiException; import com.bytedance.ads.model.AccountFundGetV30Response; import java.util.Arrays; AccountFundGetV30Api api = new AccountFundGetV30Api(); ApiClient client = api.getApiClient(); client.setBasePath("https://api.oceanengine.com"); client.addDefaultHeader("Access-Token", "your_token"); api.setApiClient(client); AccountFundGetV30Response response = api.openApiV30AccountFundGetGet( Arrays.asList(123456L), null, null ); ``` ### Response #### Success Response (200) - **data** (Object) - Contains the fund information for the requested accounts. #### Response Example ```json { "data": { ... } } ``` ``` -------------------------------- ### Pair Class Usage Example Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/api-reference/05-HelperClasses.md Demonstrates how to create and populate a list of Pair objects for API parameters. ```java import com.bytedance.ads.Pair; import java.util.ArrayList; import java.util.List; // 创建参数列表 List params = new ArrayList<>(); params.add(new Pair("account_ids", "123456")); params.add(new Pair("account_type", "ACCOUNT")); params.add(new Pair("grant_type_split", "1")); // 或者使用 Arrays.asList params = Arrays.asList( new Pair("key1", "value1"), new Pair("key2", "value2") ); ``` -------------------------------- ### Minimal API Request Example Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/目录和概览.md This snippet shows the most basic way to initialize the SDK and make a common API request. Ensure you replace 'your_token' with your actual access token and adjust the endpoint and parameters as needed. ```java ApiClient apiClient = new ApiClient(); apiClient.setBasePath("https://api.oceanengine.com"); apiClient.addDefaultHeader("Access-Token", "your_token"); Configuration.setDefaultApiClient(apiClient); CommonReqApi api = new CommonReqApi(); CommonResponse response = api.commonReq( "GET", "/open_api/v3.0/account/fund/get/", null, Arrays.asList(new Pair("account_ids", "123456")), null, null ); ``` -------------------------------- ### DouplusOrderReportV30Api Example Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/README.md Example of how to use the DouplusOrderReportV30Api to retrieve order reports. This includes setting up parameters like awemeSecUid, statTime, groupBy, and filter. ```APIDOC ## DouplusOrderReportV30Api Example This example demonstrates calling the `openApiV30DouplusOrderReportGet` method from the `DouplusOrderReportV30Api` class. ### Method ```java public static void main(String[] args) throws ApiException { DouplusOrderReportV30ApiExample example = new DouplusOrderReportV30ApiExample(); example.setCase(); ApiClient apiClient = api.getApiClient(); apiClient.addDefaultHeader("Access-Token", "80914d2cfd258e4d75aab50250bbbc4c84ceaaf6"); api.setApiClient(apiClient); DouplusOrderReportV30Response response = api.openApiV30DouplusOrderReportGet(example.awemeSecUid, example.statTime, example.groupBy, example.filter, example.pageSize, example.page); System.out.println(response); } ``` ### Endpoint `/open_api/v3.0/douplus/order/report/` ### Parameters - **awemeSecUid** (String) - Required - The unique identifier for the Aweme account. - **statTime** (DouplusOrderReportV30StatTime) - Required - The time range for statistics. - **groupBy** (List) - Optional - The fields to group the report by. - **filter** (DouplusOrderReportV30Filter) - Optional - Filters for the report data. - **pageSize** (Long) - Optional - The number of results per page. - **page** (Long) - Optional - The page number. ``` -------------------------------- ### Asynchronous API Workflow Example Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/endpoints.md This example illustrates the workflow for using asynchronous APIs. It covers creating an asynchronous task, polling its status, and retrieving results upon completion or failure. ```APIDOC ## Asynchronous API Operations ### Description This section details the process for interacting with asynchronous APIs, which are suitable for long-running operations. The workflow involves creating a task, monitoring its progress, and fetching the results. ### Method POST (for task creation), GET (for status polling) ### Endpoints - **Task Creation**: /open_api/v3.0/async/task/create/ - **Task Status Check**: /open_api/v3.0/async/task/get/ ### Workflow 1. **Create Asynchronous Task**: Initiate a long-running operation by sending a POST request to the task creation endpoint with the necessary task parameters. 2. **Poll Task Status**: Periodically send GET requests to the task status endpoint, using the `task_id` obtained from the creation response, to check the current status of the operation. 3. **Handle Task Completion or Failure**: Once the task status indicates 'DONE', retrieve the result URL. If the status is 'FAILED', handle the error appropriately. ### Request Parameters (Task Creation) - **taskRequest** (object) - Required - An object containing the details for the asynchronous task. ### Request Parameters (Task Status Check) - **task_id** (string) - Required - The unique identifier for the asynchronous task. ### Response (Task Creation) - **data** (object) - **task_id** (string) - The ID of the created asynchronous task. - **message** (string) - Description of the operation result. - **status_code** (integer) - The status code of the response. ### Response (Task Status Check) - **data** (object) - **status** (string) - The current status of the task (e.g., "PROCESSING", "DONE", "FAILED"). - **result_url** (string) - The URL to access the task results if the status is "DONE". - **message** (string) - Description of the operation result. - **status_code** (integer) - The status code of the response. ### Example (Polling Loop) ```java // Assume 'api' is an initialized API client instance // 1. Create async task CommonResponse createResponse = api.commonReq( "POST", "/open_api/v3.0/async/task/create/", "application/json", null, null, taskRequest ); String taskId = createResponse.getData().getAsJsonObject().get("task_id").getAsString(); // 2. Poll task status (up to 60 times) for (int i = 0; i < 60; i++) { CommonResponse statusResponse = api.commonReq( "GET", "/open_api/v3.0/async/task/get/", null, Arrays.asList(new Pair("task_id", taskId)), null, null ); JsonObject taskStatus = statusResponse.getData().getAsJsonObject(); String status = taskStatus.get("status").getAsString(); if ("DONE".equals(status)) { // Task completed, get result URL String resultUrl = taskStatus.get("result_url").getAsString(); System.out.println("Task completed. Result URL: " + resultUrl); break; } else if ("FAILED".equals(status)) { // Task failed System.out.println("Task failed."); break; } // Wait for 2 seconds before next poll Thread.sleep(2000); } ``` ``` -------------------------------- ### 通用 API 调用 - GET 请求 Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/快速开始.md 使用 `CommonReqApi` 进行 GET 请求调用未生成代码的接口。 ```APIDOC ## 通用 API 调用 如果想使用 SDK 调用未生成代码的接口,可使用 `CommonReqApi` 进行调用: #### GET 请求 ```java import com.bytedance.ads.api.CommonReqApi; import com.bytedance.ads.Pair; import com.bytedance.ads.model.CommonResponse; import java.util.Arrays; import java.util.List; CommonReqApi api = new CommonReqApi(); List queryParams = Arrays.asList( new Pair("account_ids", "123456") ); try { CommonResponse response = api.commonReq( "GET", "/open_api/v3.0/account/fund/get/", null, // contentType queryParams, // 查询参数 null, // formParams null // requestBody ); System.out.println(response); } catch (ApiException e) { System.err.println("API 调用失败: " + e.getMessage()); } ``` ``` -------------------------------- ### Form Encoded POST Request Example Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/api-reference/03-CommonReqApi.md This example demonstrates how to make a form-encoded POST request to operate on a campaign. ```APIDOC ## POST /open_api/v3.0/campaign/operate/ ### Description Performs an operation on a campaign, such as pausing it. ### Method POST ### Endpoint /open_api/v3.0/campaign/operate/ ### Parameters #### Request Body - **account_id** (integer) - Required - The ID of the account. - **operation** (string) - Required - The operation to perform (e.g., "pause"). ### Request Example ```json { "account_id": 123456, "operation": "pause" } ``` ### Response #### Success Response (200) - **code** (integer) - The response code. - **data** (object) - The data returned from the API, indicating the operation result. #### Response Example ```json { "code": 200, "data": { "success": true } } ``` ``` -------------------------------- ### 通用 API 调用 - GET 请求 Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/快速开始.md 使用 `CommonReqApi` 进行 GET 请求,适用于调用未生成代码的接口。需要指定请求方法、URL 和查询参数。 ```java import com.bytedance.ads.api.CommonReqApi; import com.bytedance.ads.Pair; import com.bytedance.ads.model.CommonResponse; import java.util.Arrays; import java.util.List; CommonReqApi api = new CommonReqApi(); List queryParams = Arrays.asList( new Pair("account_ids", "123456") ); try { CommonResponse response = api.commonReq( "GET", "/open_api/v3.0/account/fund/get/", null, // contentType queryParams, // 查询参数 null, // formParams null // requestBody ); System.out.println(response); } catch (ApiException e) { System.err.println("API 调用失败: " + e.getMessage()); } ``` -------------------------------- ### Batch Update API Example Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/endpoints.md This example demonstrates how to perform a batch update operation for resources using the commonReq method. It shows how to construct the request body with multiple items to be updated. ```APIDOC ## Batch Update API ### Description This endpoint supports batch updates for resources, allowing multiple resources to be modified in a single request. ### Method POST ### Endpoint /open_api/v3.0/resource/batch/update/ ### Request Body - **items** (array) - Required - An array of objects, where each object represents a resource to be updated. - **id** (integer) - Required - The ID of the resource. - **status** (string) - Required - The new status to set for the resource (e.g., "PAUSED"). ### Request Example ```json { "items": [ { "id": 123456, "status": "PAUSED" }, { "id": 123457, "status": "PAUSED" } // ... more items ] } ``` ### Response #### Success Response (200) - **data** (object) - Contains the result of the batch operation. - **message** (string) - Description of the operation result. - **status_code** (integer) - The status code of the response. #### Response Example ```json { "data": {}, "message": "success", "status_code": 0 } ``` ``` -------------------------------- ### Form Encoded POST Request Example Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/api-reference/03-CommonReqApi.md This example shows how to send data as form parameters. The 'contentType' should be set to 'application/x-www-form-urlencoded'. ```java import java.util.HashMap; import java.util.Map; Map formParams = new HashMap<>(); formParams.put("account_id", 123456); formParams.put("operation", "pause"); CommonResponse response = api.commonReq( "POST", "/open_api/v3.0/campaign/operate/", "application/x-www-form-urlencoded", null, formParams, null ); ``` -------------------------------- ### Multi-parameter GET Request Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/api-reference/03-CommonReqApi.md Shows how to include multiple query parameters in a GET request. The parameters are provided as a List of Pair objects. ```java List queryParams = Arrays.asList( new Pair("account_ids", "123456,789012"), new Pair("account_type", "ACCOUNT"), new Pair("grant_type_split", "1") ); CommonResponse response = api.commonReq( "GET", "/open_api/v3.0/account/fund/get/", null, queryParams, null, null ); ``` -------------------------------- ### POST Request with Query Parameters Example Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/api-reference/03-CommonReqApi.md Demonstrates making a POST request that includes query parameters along with a JSON request body. The 'contentType' is set to 'application/json'. ```java JsonObject body = new JsonObject(); body.addProperty("data", "some_data"); List queryParams = Arrays.asList( new Pair("account_id", "123456") ); CommonResponse response = api.commonReq( "POST", "/open_api/v3.0/some/endpoint/", "application/json", queryParams, null, body ); ``` -------------------------------- ### List and Map Data Type Examples Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/types.md Provides examples of common Java collection types used for API interactions. This includes lists of Longs and Strings, and a map for filtering criteria. ```java // List - 长整数列表 List accountIds = Arrays.asList(123456L, 789012L); // List - 字符串列表 List fields = Arrays.asList("id", "name", "status"); // Map - 字符串到对象的映射 Map filters = new HashMap<>(); filters.put("status", "active"); filters.put("created_after", "2023-01-01"); ``` -------------------------------- ### Pagination API Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/endpoints.md Explains how to handle APIs that return paginated lists and provides common parameters and an example. ```APIDOC ## Pagination API Certain APIs that return list data support pagination. ### Common Pagination Parameters | Parameter | Type | Description | |-----------|------|-------------| | page | Long | Current page number, starting from 1 | | page_size | Long | Number of records per page, maximum 100-1000 (depends on the API) | ### Pagination Example (Java) ```java for (long page = 1; ; page++) { List params = Arrays.asList( new Pair("page", String.valueOf(page)), new Pair("page_size", "100") ); CommonResponse response = api.commonReq( "GET", "/open_api/v3.0/resource/list/", null, params, null, null ); if (response.getCode() != 0) { System.err.println("Request failed: " + response.getMessage()); break; } // Process data for the current page JsonObject data = response.getData().getAsJsonObject(); JsonArray items = data.getAsJsonArray("list"); if (items == null || items.size() == 0) { break; // No more data } for (JsonElement item : items) { processItem(item.getAsJsonObject()); } } ``` ``` -------------------------------- ### Account Update Example Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/endpoints.md Demonstrates how to perform a POST request to update account information using the `commonReq` method. ```APIDOC ## POST /open_api/v3.0/account/update/ ### Description Updates account information. This is an example of a POST request using the v3.0 API with a JSON request body. ### Method POST ### Endpoint /open_api/v3.0/account/update/ ### Parameters #### Request Body - **account_id** (Long) - Required - The ID of the account to update. - **name** (String) - Required - The new name for the account. ### Request Example ```java import com.bytedance.ads.ApiClient; import com.bytedance.ads.ApiException; import com.google.gson.JsonObject; import java.util.Arrays; // Assuming 'api' is an instance of a class that has commonReq method, like ApiClient itself or a service class ApiClient apiClient = new ApiClient(); // Or get from an existing API instance apiClient.setBasePath("https://api.oceanengine.com"); apiClient.addDefaultHeader("Access-Token", "your_token"); JsonObject body = new JsonObject(); body.addProperty("account_id", 123456); body.addProperty("name", "Updated Name"); // The commonReq method signature might vary based on the SDK implementation. // This example assumes a signature that takes method, url, contentType, queryParams, headers, body. Object response = apiClient.commonReq( "POST", "/open_api/v3.0/account/update/", "application/json", null, null, body // Request body ); ``` ### Response #### Success Response (200) - **code** (Integer) - The response code. - **message** (String) - The response message. #### Response Example ```json { "code": 0, "message": "Success" } ``` ``` -------------------------------- ### Global Configuration for All APIs Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/api-reference/04-Configuration.md Configures a single ApiClient instance globally at application startup. All API instances created thereafter will automatically use this client, simplifying setup. ```java import com.bytedance.ads.ApiClient; import com.bytedance.ads.Configuration; import com.bytedance.ads.api.AccountFundGetV30Api; import com.bytedance.ads.api.CampaignGetV2Api; public class Application { public static void main(String[] args) { // 在应用启动时配置一次 ApiClient apiClient = new ApiClient(); apiClient.setBasePath("https://api.oceanengine.com"); apiClient.addDefaultHeader("Access-Token", "your_access_token"); apiClient.setDebugging(true); Configuration.setDefaultApiClient(apiClient); // 之后创建的所有 API 实例都会使用这个配置 AccountFundGetV30Api fundApi = new AccountFundGetV30Api(); CampaignGetV2Api campaignApi = new CampaignGetV2Api(); // 两个实例都会使用配置好的 apiClient } ``` -------------------------------- ### Configure ApiKey Authentication Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/authentication.md Example of how to configure API Key authentication for an ApiClient. Ensure the ApiKeyAuth is retrieved from the ApiClient and then set with the appropriate token and optional prefix. ```java import com.bytedance.ads.auth.ApiKeyAuth; import com.bytedance.ads.ApiClient; ApiClient apiClient = new ApiClient(); // 获取已配置的认证 ApiKeyAuth auth = (ApiKeyAuth) apiClient.getAuthentication("ApiKeyAuth"); // 设置 API Key auth.setApiKey("your_access_token_here"); // 可选:设置前缀 // auth.setApiKeyPrefix("Bearer"); ``` -------------------------------- ### Minimal Initialization Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/README.md Initialize the SDK with your access token and base path in under 30 seconds. ```APIDOC ## Minimal Initialization ### Description Initialize the SDK with your access token and base path in under 30 seconds. ### Method ```java import com.bytedance.ads.ApiClient; import com.bytedance.ads.Configuration; ApiClient apiClient = new ApiClient(); apiClient.setBasePath("https://api.oceanengine.com"); apiClient.addDefaultHeader("Access-Token", "your_access_token"); Configuration.setDefaultApiClient(apiClient); ``` ``` -------------------------------- ### Initialize API Client and Make a Request Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/api-reference/04-Configuration.md Demonstrates the complete initialization process for the SDK, including setting the base path, access token, and debugging mode. It then shows how to set this client as the default and use it to instantiate an API and make a request. ```java import com.bytedance.ads.ApiClient; import com.bytedance.ads.Configuration; import com.bytedance.ads.api.AccountFundGetV30Api; import com.bytedance.ads.api.CampaignGetV2Api; import com.bytedance.ads.model.AccountFundGetV30Response; public class Main { public static void main(String[] args) { try { // 1. 创建和配置 API 客户端 ApiClient apiClient = new ApiClient(); apiClient.setBasePath("https://api.oceanengine.com"); apiClient.addDefaultHeader("Access-Token", "your_access_token"); // 启用调试模式查看请求和响应 apiClient.setDebugging(false); // 生产环境应设为 false // 2. 设置为全局默认客户端 Configuration.setDefaultApiClient(apiClient); // 3. 创建 API 实例(自动使用全局客户端) AccountFundGetV30Api fundApi = new AccountFundGetV30Api(); // 4. 调用 API 方法 AccountFundGetV30Response response = fundApi.openApiV30AccountFundGetGet( Arrays.asList(123456L), null, null ); System.out.println("Response Code: " + response.getCode()); System.out.println("Response Message: " + response.getMessage()); } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### Common API Request and Response Handling Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/types.md Example of making a common API request using CommonReqApi and handling the CommonResponse. It demonstrates checking the response code and accessing data or error messages. ```java import com.bytedance.ads.api.CommonReqApi; import com.bytedance.ads.model.CommonResponse; CommonReqApi api = new CommonReqApi(); CommonResponse response = api.commonReq( "GET", "/open_api/v3.0/account/fund/get/", null, params, null, null ); // 检查响应 if (response.getCode() == 0) { System.out.println("成功: " + response.getRequestId()); System.out.println("数据: " + response.getData()); } else { System.out.println("错误代码: " + response.getCode()); System.out.println("错误消息: " + response.getMessage()); } ``` -------------------------------- ### SDK Navigation by Use Case Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/README.md Quickly find relevant documentation based on your specific needs. ```text 我要快速上手 → 快速开始.md (6 分钟) 我要配置生产环境 → configuration.md (10 分钟) 我要处理错误 → errors.md (15 分钟) 我要调用某个 API → endpoints.md (5 分钟) 我要了解某个类 → api-reference/*.md (10 分钟) 我要完整理解 → 目录和概览.md (20 分钟) ``` -------------------------------- ### GET Request Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/api-reference/03-CommonReqApi.md This snippet demonstrates how to make a GET request using the commonReq method. It supports query parameters. ```APIDOC ## GET Request ### Description This endpoint facilitates making GET requests. It supports query parameters. ### Method GET ### Endpoint /commonReq ### Parameters #### Query Parameters - **param** (type) - Required/Optional - Description of the query parameter ``` -------------------------------- ### Asynchronous GET Request Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/api-reference/03-CommonReqApi.md This snippet demonstrates how to make an asynchronous GET request using the commonReqAsync method. It supports query parameters. ```APIDOC ## Asynchronous GET Request ### Description This endpoint facilitates making asynchronous GET requests. It supports query parameters. ### Method GET ### Endpoint /commonReqAsync ### Parameters #### Query Parameters - **param** (type) - Required/Optional - Description of the query parameter ``` -------------------------------- ### Create AccountFundGetV30Api Instance Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/endpoints.md Instantiate the AccountFundGetV30Api class to begin API interactions. Ensure the necessary import is present. ```java import com.bytedance.ads.api.AccountFundGetV30Api; AccountFundGetV30Api api = new AccountFundGetV30Api(); ``` -------------------------------- ### Construct Query Parameters for GET Request Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/endpoints.md Build a list of query parameters for GET requests using the Pair class. This is used for filtering or specifying data in the URL. ```java import com.bytedance.ads.Pair; import java.util.Arrays; import java.util.List; List queryParams = Arrays.asList( new Pair("account_ids", "123456,789012"), new Pair("account_type", "ACCOUNT") ); // Assuming 'api' is an instance of a relevant API class and 'response' is declared // response = api.commonReq( // "GET", // "/open_api/v3.0/account/fund/get/", // null, // queryParams, // 查询参数 // null, // null // ); ``` -------------------------------- ### Calling an API Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/README.md Demonstrates how to make a basic API call using the CommonReqApi. ```APIDOC ## Calling an API ### Description Demonstrates how to make a basic API call using the CommonReqApi. ### Method ```java import com.bytedance.ads.api.CommonReqApi; import com.bytedance.ads.model.CommonResponse; CommonReqApi api = new CommonReqApi(); CommonResponse response = api.commonReq( "GET", "/open_api/v3.0/account/fund/get/", null, Arrays.asList(new Pair("account_ids", "123456")), null, null ); if (response.getCode() == 0) { System.out.println("成功: " + response.getData()); } ``` ``` -------------------------------- ### Initialize ApiClient Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/README.md This snippet shows how to initialize the ApiClient, set the base path, and add default headers such as the Access-Token. ```APIDOC ## Initialize ApiClient > You can initialize the client as shown below and modify its properties. ```java public static void main(String[] args) throws ApiException { ApiClient apiClient = new ApiClient(); apiClient.setBasePath("https://api.oceanengine.com"); apiClient.addDefaultHeader("Access-Token", "test"); api.setApiClient(apiClient); } ``` ``` -------------------------------- ### Maven 仓库配置 Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/快速开始.md 配置 Maven 仓库以正确下载 SDK。如果使用镜像源,请在 `settings.xml` 中排除该仓库。 ```xml OceanengineOpenApi ad_open_sdk_java default https://artifact.bytedance.com/repository/releases/ ``` ```xml aliyunmaven *,!OceanengineOpenApi 阿里云公共仓库 https://maven.aliyun.com/repository/public ``` -------------------------------- ### GET Request with CSV formatted parameters Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/api-reference/03-CommonReqApi.md Illustrates how to pass CSV formatted values for parameters like 'ids' and 'fields' in a GET request. This is useful for batch operations or specifying multiple values for a single parameter. ```java List queryParams = new ArrayList<>(); queryParams.add(new Pair("ids", "1,2,3,4,5")); queryParams.add(new Pair("fields", "id,name,status")); CommonResponse response = api.commonReq( "GET", "/open_api/v3.0/ad/get/", null, queryParams, null, null ); ``` -------------------------------- ### 辅助类 - 其他支持类 Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/目录和概览.md SDK 提供了多种辅助类,包括 ApiResponse(响应包装类)、ApiCallback(异步回调接口)、Pair(键值对类)、JSON(JSON 序列化工具)、StringUtil(字符串工具)、ServerConfiguration(服务器配置)和 GzipRequestInterceptor(压缩拦截器)。 ```APIDOC ## 辅助类 - 其他支持类 ### Description SDK 提供了多种辅助类,包括 ApiResponse(响应包装类)、ApiCallback(异步回调接口)、Pair(键值对类)、JSON(JSON 序列化工具)、StringUtil(字符串工具)、ServerConfiguration(服务器配置)和 GzipRequestInterceptor(压缩拦截器)。 ``` -------------------------------- ### DpaAlbumStatusGetV30Api Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/README.md Gets the status of a DPA album. ```APIDOC ## GET /open_api/v3.0/dpa/album_status/get/ ### Description Gets the status of a DPA album. ### Method GET ### Endpoint /open_api/v3.0/dpa/album_status/get/ ``` -------------------------------- ### DouplusRtaGetInfoV30Api Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/README.md Gets RTA information for Douplus. ```APIDOC ## GET /open_api/v3.0/douplus/rta/get_info/ ### Description Gets RTA information for Douplus. ### Method GET ### Endpoint /open_api/v3.0/douplus/rta/get_info/ ``` -------------------------------- ### Minimal API Client Configuration Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/configuration.md Initialize an ApiClient with essential settings, including the base path and an access token. This configuration is suitable for basic usage. ```java import com.bytedance.ads.ApiClient; import com.bytedance.ads.Configuration; ApiClient apiClient = new ApiClient(); apiClient.setBasePath("https://api.oceanengine.com"); apiClient.addDefaultHeader("Access-Token", "your_token"); Configuration.setDefaultApiClient(apiClient); ``` -------------------------------- ### DpaEbpProductCreateV30Api Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/README.md Creates a new product. ```APIDOC ## POST /open_api/v3.0/dpa/ebp/product/create/ ### Description Creates a new product. ### Method POST ### Endpoint /open_api/v3.0/dpa/ebp/product/create/ ``` -------------------------------- ### Creative Get Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/endpoints.md Retrieves creative information. ```APIDOC ## GET /open_api/2/creative/get/ ### Description Retrieves creative information. ### Method GET ### Endpoint /open_api/2/creative/get/ ### Response #### Success Response (200) - **data** (object) - Creative details. ``` -------------------------------- ### Specific API with Different Client Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/api-reference/04-Configuration.md Demonstrates how to use a specific API instance with a client different from the global default. This is useful for scenarios requiring distinct configurations for certain operations. ```java import com.bytedance.ads.ApiClient; import com.bytedance.ads.Configuration; import com.bytedance.ads.api.AccountFundGetV30Api; // 全局默认配置 ApiClient defaultClient = new ApiClient(); defaultClient.addDefaultHeader("Access-Token", "default_token"); Configuration.setDefaultApiClient(defaultClient); // 创建一个特定的 API 实例时,可以使用不同的客户端 ApiClient specialClient = new ApiClient(); specialClient.addDefaultHeader("Access-Token", "special_token"); AccountFundGetV30Api specialApi = new AccountFundGetV30Api(specialClient); // 这个 specialApi 会使用 specialClient 而不是全局默认的 AccountFundGetV30Api defaultApi = new AccountFundGetV30Api(); // 这个 defaultApi 会使用全局默认的 Configuration.getDefaultApiClient() ``` -------------------------------- ### Campaign Get Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/endpoints.md Retrieves campaign information. ```APIDOC ## GET /open_api/2/campaign/get/ ### Description Retrieves campaign information. ### Method GET ### Endpoint /open_api/2/campaign/get/ ### Response #### Success Response (200) - **data** (object) - Campaign details. ``` -------------------------------- ### Load Configuration from Properties File Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/authentication.md Read token and base URL from an `application.properties` file using Java's Properties class. This allows for externalized configuration. ```java import java.io.InputStream; import java.util.Properties; Properties props = new Properties(); InputStream input = getClass().getClassLoader() .getResourceAsStream("application.properties"); props.load(input); String token = props.getProperty("access.token"); String baseUrl = props.getProperty("api.base.url"); ApiClient apiClient = new ApiClient(); apiClient.setBasePath(baseUrl); apiClient.addDefaultHeader("Access-Token", token); ``` -------------------------------- ### Maven 依赖配置 Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/快速开始.md 在 `pom.xml` 文件中添加此依赖以引入 SDK。 ```xml org.openapitools oceanengine-mapi-java-client [0.0.1,) ``` -------------------------------- ### Creative Detail Get Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/endpoints.md Retrieves detailed information about creatives. ```APIDOC ## GET /open_api/v3.0/creative/detail/get/ ### Description Retrieves detailed information about creatives. ### Method GET ### Endpoint /open_api/v3.0/creative/detail/get/ ### Response #### Success Response (200) - **data** (object) - Creative details. ``` -------------------------------- ### Ad Get Source: https://github.com/oceanengine/ad_open_sdk_java/blob/main/_autodocs/endpoints.md Retrieves information about ads. Supports filtering and pagination. ```APIDOC ## GET /open_api/2/ad/get/ ### Description Retrieves information about ads. ### Method GET ### Endpoint /open_api/2/ad/get/ ### Response #### Success Response (200) - **data** (object) - Ad details. ```