### Install Marketing Go SDK Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Use the go get command to add the SDK dependency to your project. ```bash go get github.com/oceanengine/ad_open_sdk_go ``` -------------------------------- ### Install Marketing Go SDK Source: https://github.com/oceanengine/ad_open_sdk_go/blob/master/README.md Use this command to install the Go SDK for the OceanEngine Ad Open Platform. ```shell go get git@github.com:oceanengine/ad_open_sdk_go.git ``` -------------------------------- ### Get Advertiser Data Report (Go) Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Query advertiser-level data reports with specified date ranges, fields, and time granularity. This example fetches daily statistics for a given period. Ensure the date format is correct. ```go package main import ( "context" "fmt" "io" ad_open_sdk_go "github.com/oceanengine/ad_open_sdk_go" "github.com/oceanengine/ad_open_sdk_go/config" . "github.com/oceanengine/ad_open_sdk_go/models" ) func main() { const accessToken = "your_access_token" ctx := context.Background() configuration := config.NewConfiguration() apiClient := ad_open_sdk_go.Init(configuration) apiClient.SetLogEnable(true) startDate := "2024-01-01" endDate := "2024-01-31" resp, httpRes, err := apiClient.ReportAdvertiserGetV2Api(). Get(ctx). AccessToken(accessToken). AdvertiserId(1234567890). // 广告主ID StartDate(&startDate). // 开始日期 EndDate(&endDate). // 结束日期 Fields([]string{ // 返回字段 "cost", "show", "click", "convert", }). TimeGranularity(ReportAdvertiserGetV2TimeGranularity("STAT_TIME_GRANULARITY_DAILY") ). Page(1). PageSize(100). Execute() if err != nil { fmt.Printf("Error: %v\n", err) return } fmt.Printf("Report Data: %s\n", ToJsonString(resp)) resBytes, _ := io.ReadAll(httpRes.Body) fmt.Printf("Raw Response: %s\n", string(resBytes)) } ``` -------------------------------- ### Example Authentication Middleware Source: https://github.com/oceanengine/ad_open_sdk_go/blob/master/README.md An example implementation of an authentication middleware that adds an 'Access-Token' header to requests if a token is present in the context. ```golang func AuthMiddleware(next api.Endpoint) api.Endpoint { return func(ctx context.Context, req *http.Request) (resp *http.Response, err error) { token := ctx.Value(config.ContextAccessToken) if token != nil { if tokenStr, ok := token.(string); ok { req.Header.Set("Access-Token", tokenStr) } } return next(ctx, req) } } ``` -------------------------------- ### Get Project List using Go SDK Source: https://github.com/oceanengine/ad_open_sdk_go/blob/master/README.md Demonstrates how to initialize the SDK client, set configuration, and call the Project List API. Ensure you replace 'ACCESS_TOKEN' with a valid token. The client is designed to be reused. ```go package main import ( "context" "encoding/json" "fmt" "io" "log" ad_open_sdk_go "github.com/oceanengine/ad_open_sdk_go" "github.com/oceanengine/ad_open_sdk_go/config" . "github.com/oceanengine/ad_open_sdk_go/models" ) // ApiOpenApiV30ProjectListGetRequestExample 接口参数 type ApiOpenApiV30ProjectListGetRequestExample struct { AdvertiserId int64 `json:"advertiser_id"` Fields []string `json:"fields,omitempty"` Filtering ProjectListV30Filtering `json:"filtering,omitempty"` Page int64 `json:"page,omitempty"` PageSize int64 `json:"page_size,omitempty"` } // url: https://api.oceanengine.com/open_api/v3.0/project/list/ Get func main() { const demoreq = `` const accessToken = "ACCESS_TOKEN" ctx := context.Background() // 初始化client,此client建议复用 configuration := config.NewConfiguration() // 可修改默认 HTTP client 为自定义 client //configuration.HTTPClient = xxxClient apiClient := ad_open_sdk_go.Init(configuration) // client修改配置 apiClient.SetLogEnable(true) apiClient.AddDefaultHeader("xxx", "xxx") var request ApiOpenApiV30ProjectListGetRequestExample err := json.Unmarshal([]byte(demoreq), &request) if err != nil { log.Fatal(err) } // 调用接口,首先使用 xxxApi() 方法获取 service resp, httpRes, err := apiClient.ProjectListV30Api(). // 通过 Get/Post 方法获取 Request Get(ctx). // 传入接口参数,Get 请求通过链式调用传入参数,Post 请求通过结构体传入参数 AccessToken(accessToken). AdvertiserId(request.AdvertiserId).Fields(request.Fields).Filtering(request.Filtering).Page(request.Page).PageSize(request.PageSize). // 调用 Execute 方法执行请求 Execute() // 接口会返回 resp 结构体、原生 http response、error fmt.Println(ToJsonString(resp)) resBytes, _ := io.ReadAll(httpRes.Body) fmt.Println(string(resBytes)) fmt.Println(err) } ``` -------------------------------- ### GET /open_api/2/ad/get/ Source: https://github.com/oceanengine/ad_open_sdk_go/blob/master/README.md Retrieves advertisement details. ```APIDOC ## GET /open_api/2/ad/get/ ### Description Fetches information for specific advertisements. ### Method GET ### Endpoint /open_api/2/ad/get/ ``` -------------------------------- ### Import SDK Package Source: https://github.com/oceanengine/ad_open_sdk_go/blob/master/README.md Import the SDK package into your Go project to start using its functionalities. ```golang import ad_open_sdk_go "github.com/oceanengine/ad_open_sdk_go ``` -------------------------------- ### GET /open_api/2/user/info/ Source: https://github.com/oceanengine/ad_open_sdk_go/blob/master/README.md Retrieves user information. ```APIDOC ## GET /open_api/2/user/info/ ### Description Retrieves basic profile information for the authenticated user. ### Method GET ### Endpoint /open_api/2/user/info/ ``` -------------------------------- ### Upload Video Ad Material (Go) Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Upload video ad materials via URL or file. This example shows uploading via URL with parameters like advertiser ID, filename, video signature, and labels. Ensure the video URL is accessible. ```go package main import ( "context" "fmt" "io" ad_open_sdk_go "github.com/oceanengine/ad_open_sdk_go" "github.com/oceanengine/ad_open_sdk_go/config" . "github.com/oceanengine/ad_open_sdk_go/models" ) func main() { const accessToken = "your_access_token" ctx := context.Background() configuration := config.NewConfiguration() apiClient := ad_open_sdk_go.Init(configuration) apiClient.SetLogEnable(true) resp, httpRes, err := apiClient.FileVideoAdV2Api(). Post(ctx). AccessToken(accessToken). AdvertiserId(1234567890). // 广告主ID Filename("video_ad.mp4"). // 文件名 VideoSignature("md5_signature"). // 视频 MD5 签名 VideoUrl("https://example.com/video.mp4"). // 视频 URL // VideoFile(&FormFileInfo{}). // 或上传文件 Labels([]string{"brand", "product"}). // 标签 IsAigc(false). // 是否 AIGC 生成 Execute() if err != nil { fmt.Printf("Error: %v\n", err) return } fmt.Printf("Uploaded Video: %s\n", ToJsonString(resp)) resBytes, _ := io.ReadAll(httpRes.Body) fmt.Printf("Raw Response: %s\n", string(resBytes)) } ``` -------------------------------- ### GET /open_api/2/advertiser/info/ Source: https://github.com/oceanengine/ad_open_sdk_go/blob/master/README.md Retrieves advertiser information. ```APIDOC ## GET /open_api/2/advertiser/info/ ### Description Retrieves basic information about the advertiser. ### Method GET ### Endpoint /open_api/2/advertiser/info/ ``` -------------------------------- ### Get Ad Project List (v3.0) in Go Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Use this to query a list of ad projects, supporting pagination and filtering. Ensure you have a valid access token and advertiser ID. ```go package main import ( "context" "fmt" "io" ad_open_sdk_go "github.com/oceanengine/ad_open_sdk_go" "github.com/oceanengine/ad_open_sdk_go/config" . "github.com/oceanengine/ad_open_sdk_go/models" ) func main() { const accessToken = "your_access_token" ctx := context.Background() configuration := config.NewConfiguration() apiClient := ad_open_sdk_go.Init(configuration) apiClient.SetLogEnable(true) // 构建筛选条件 filtering := ProjectListV30Filtering{ // 可设置筛选条件 } resp, httpRes, err := apiClient.ProjectListV30Api(). Get(ctx). AccessToken(accessToken). AdvertiserId(1234567890). // 广告主ID Fields([]string{"id", "name", "budget"}). // 返回字段 Filtering(filtering). // 筛选条件 Page(1). // 页码 PageSize(20). // 每页数量 Execute() if err != nil { fmt.Printf("Error: %v\n", err) return } fmt.Printf("Project List: %s\n", ToJsonString(resp)) resBytes, _ := io.ReadAll(httpRes.Body) fmt.Printf("Raw Response: %s\n", string(resBytes)) } ``` -------------------------------- ### GET /open_api/v3.0/tools/wechat_game/list/ Source: https://github.com/oceanengine/ad_open_sdk_go/blob/master/README.md Retrieves a list of WeChat games. ```APIDOC ## GET /open_api/v3.0/tools/wechat_game/list/ ### Description Fetches the list of WeChat games associated with the account. ### Method GET ### Endpoint /open_api/v3.0/tools/wechat_game/list/ ``` -------------------------------- ### Query DMP Custom Audience List (Go) Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Query a list of custom audience packages for targeting purposes. This example retrieves all custom audiences with specified offset and limit. Ensure the advertiser ID is correct. ```go package main import ( "context" "fmt" "io" ad_open_sdk_go "github.com/oceanengine/ad_open_sdk_go" "github.com/oceanengine/ad_open_sdk_go/config" . "github.com/oceanengine/ad_open_sdk_go/models" ) func main() { const accessToken = "your_access_token" ctx := context.Background() configuration := config.NewConfiguration() apiClient := ad_open_sdk_go.Init(configuration) apiClient.SetLogEnable(true) resp, httpRes, err := apiClient.DmpCustomAudienceSelectV2Api(). Get(ctx). AccessToken(accessToken). AdvertiserId(1234567890). // 广告主ID SelectType(DmpCustomAudienceSelectV2SelectType("CUSTOM_AUDIENCE_SELECT_TYPE_ALL")). Offset(0). // 偏移量 Limit(20). // 返回数量 Execute() if err != nil { fmt.Printf("Error: %v\n", err) return } fmt.Printf("Audience List: %s\n", ToJsonString(resp)) resBytes, _ := io.ReadAll(httpRes.Body) fmt.Printf("Raw Response: %s\n", string(resBytes)) } ``` -------------------------------- ### GET /open_api/v3.0/account/fund/get/ Source: https://github.com/oceanengine/ad_open_sdk_go/blob/master/README.md Retrieves account fund information. ```APIDOC ## GET /open_api/v3.0/account/fund/get/ ### Description Retrieves the current fund information for the specified account. ### Method GET ### Endpoint /open_api/v3.0/account/fund/get/ ``` -------------------------------- ### GET /api/v3/project/list Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Retrieves a list of ad projects, supporting pagination and filtering. ```APIDOC ## GET /api/v3/project/list ### Description Queries the list of ad projects, supporting pagination and filtering conditions. ### Method GET ### Endpoint /api/v3/project/list ### Parameters #### Query Parameters - **access_token** (string) - Required - Access token for authentication. - **advertiser_id** (integer) - Required - The ID of the advertiser. - **fields** (array of strings) - Optional - Specifies the fields to return in the response (e.g., "id", "name", "budget"). - **filtering** (object) - Optional - Filtering conditions for the project list. - **page** (integer) - Optional - The page number for pagination. Defaults to 1. - **page_size** (integer) - Optional - The number of items per page. Defaults to 20. ### Request Example ```json { "access_token": "your_access_token", "advertiser_id": 1234567890, "fields": ["id", "name", "budget"], "filtering": {}, "page": 1, "page_size": 20 } ``` ### Response #### Success Response (200) - **data** (object) - Contains the list of projects and pagination information. - **list** (array) - List of project objects. - **id** (integer) - Project ID. - **name** (string) - Project name. - **budget** (number) - Project budget. - **message** (string) - Success message. - **code** (integer) - Response code. #### Response Example ```json { "data": { "list": [ { "id": 1001, "name": "Project Alpha", "budget": 5000.00 } ], "page_info": { "page": 1, "page_size": 20, "total_number": 100, "total_page": 5 } }, "message": "success", "code": 0 } ``` ``` -------------------------------- ### GET /dmp/custom_audience/select/v2 Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Queries the list of custom audience packages (DMP) for targeted advertising. ```APIDOC ## GET /dmp/custom_audience/select/v2 ### Description Queries custom audience packages list for targeted delivery. ### Method GET ### Parameters #### Query Parameters - **AdvertiserId** (int64) - Required - Advertiser ID - **SelectType** (string) - Required - Selection type (e.g., CUSTOM_AUDIENCE_SELECT_TYPE_ALL) - **Offset** (int) - Optional - Pagination offset - **Limit** (int) - Optional - Number of records to return ``` -------------------------------- ### Perform Common API Requests in Go Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Use CommonApi to execute GET, POST, and POST Multipart requests for endpoints without generated code. Ensure the access token and request parameters are correctly configured for each method. ```go package main import ( "context" "fmt" "io" "os" ad_open_sdk_go "github.com/oceanengine/ad_open_sdk_go" "github.com/oceanengine/ad_open_sdk_go/api" "github.com/oceanengine/ad_open_sdk_go/config" . "github.com/oceanengine/ad_open_sdk_go/models" ) func main() { const accessToken = "your_access_token" ctx := context.Background() configuration := config.NewConfiguration() apiClient := ad_open_sdk_go.Init(configuration) apiClient.SetLogEnable(true) // GET 请求示例 resp, httpRes, err := apiClient.CommonApi().Get(ctx, "/open_api/2/advertiser/info/"). AccessToken(accessToken). RequestQuery(map[string]interface{}{ "advertiser_ids": []int64{1234567890}, }).Execute() fmt.Printf("GET Response: %s\n", ToJsonString(resp)) // POST 请求示例 resp, httpRes, err = apiClient.CommonApi().Post(ctx, "/open_api/oauth2/access_token/"). RequestBody(map[string]interface{}{ "app_id": 1234567890, "secret": "your_secret", "auth_code": "auth_code", }).Execute() fmt.Printf("POST Response: %s\n", ToJsonString(resp)) // POST Multipart 文件上传示例 fileBytes, _ := os.ReadFile("video.mp4") resp, httpRes, err = apiClient.CommonApi().PostMultipart(ctx, "/open_api/2/file/video/ad/"). AccessToken(accessToken). RequestForm(map[string]interface{}{ "advertiser_id": 1234567890, }). RequestFile(map[string]api.FormFile{ "video_file": { FileBytes: fileBytes, FileName: "video.mp4", }, }).Execute() fmt.Printf("Upload Response: %s\n", ToJsonString(resp)) resBytes, _ := io.ReadAll(httpRes.Body) fmt.Printf("Raw Response: %s\n", string(resBytes)) } ``` -------------------------------- ### File Video Operations API Source: https://github.com/oceanengine/ad_open_sdk_go/blob/master/README.md APIs for managing video files within the Oceanengine ad platform, including getting, deleting, clearing tasks, pausing, and updating videos. ```APIDOC ## GET /open_api/2/file/video/aweme/get/ ### Description Retrieves information about Aweme videos associated with files. ### Method GET ### Endpoint /open_api/2/file/video/aweme/get/ ## POST /open_api/2/file/video/delete/ ### Description Deletes video files from the Oceanengine ad platform. ### Method POST ### Endpoint /open_api/2/file/video/delete/ ## GET /open_api/2/file/video/efficiency/get/ ### Description Retrieves efficiency data for video files. ### Method GET ### Endpoint /open_api/2/file/video/efficiency/get/ ## GET /open_api/2/file/video/get/ ### Description Retrieves general information about video files. ### Method GET ### Endpoint /open_api/2/file/video/get/ ## POST /open_api/2/file/video/material/clear_task/create/ ### Description Creates a task to clear video material. ### Method POST ### Endpoint /open_api/2/file/video/material/clear_task/create/ ## GET /open_api/2/file/video/material/clear_task/get/ ### Description Retrieves the status of video material clear tasks. ### Method GET ### Endpoint /open_api/2/file/video/material/clear_task/get/ ## GET /open_api/2/file/video/material/clear_task_result/get/ ### Description Retrieves the results of video material clear tasks. ### Method GET ### Endpoint /open_api/2/file/video/material/clear_task_result/get/ ## POST /open_api/2/file/video/pause/ ### Description Pauses the processing or availability of a video file. ### Method POST ### Endpoint /open_api/2/file/video/pause/ ## POST /open_api/2/file/video/update/ ### Description Updates an existing video file. ### Method POST ### Endpoint /open_api/2/file/video/update/ ## GET /open_api/2/file/video/upload_task/list/ ### Description Retrieves a list of video upload tasks. ### Method GET ### Endpoint /open_api/2/file/video/upload_task/list/ ``` -------------------------------- ### GET /report/advertiser/get/v2 Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Retrieves advertiser-level performance reports with support for multi-dimensional grouping and time granularity. ```APIDOC ## GET /report/advertiser/get/v2 ### Description Queries advertiser-level data reports, supporting multi-dimensional grouping and time granularity settings. ### Method GET ### Parameters #### Query Parameters - **AdvertiserId** (int64) - Required - Advertiser ID - **StartDate** (string) - Required - Start date (YYYY-MM-DD) - **EndDate** (string) - Required - End date (YYYY-MM-DD) - **Fields** (array) - Required - List of metrics to return - **TimeGranularity** (string) - Required - Time granularity (e.g., STAT_TIME_GRANULARITY_DAILY) - **Page** (int) - Optional - Page number - **PageSize** (int) - Optional - Number of records per page ``` -------------------------------- ### Initialize SDK with Default Configuration Source: https://github.com/oceanengine/ad_open_sdk_go/blob/master/README.md Create a new configuration object using the default settings for the SDK. This is the first step before initializing the client. ```golang import "github.com/oceanengine/ad_open_sdk_go/config" configuration := config.NewConfiguration() ``` -------------------------------- ### Initialize SDK Client Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Configure the API client with custom settings such as host, logging, and HTTP client timeouts. ```go package main import ( "net/http" "time" ad_open_sdk_go "github.com/oceanengine/ad_open_sdk_go" "github.com/oceanengine/ad_open_sdk_go/config" ) func main() { // 创建默认配置 configuration := config.NewConfiguration() // 配置选项 configuration.Host = "api.oceanengine.com" // API 域名 configuration.Scheme = "https" // 协议 configuration.LogEnable = true // 启用日志 configuration.UseLogMw = true // 使用日志中间件 // 使用自定义 HTTP 客户端 configuration.HTTPClient = &http.Client{ Timeout: 30 * time.Second, } // 添加默认请求头 configuration.AddDefaultHeader("X-Debug-Mode", "1") // 初始化客户端 apiClient := ad_open_sdk_go.Init(configuration) // 运行时修改配置 apiClient.SetLogEnable(true) apiClient.SetHost("api.oceanengine.com") apiClient.AddDefaultHeader("X-Custom-Header", "value") } ``` -------------------------------- ### Initialize and Configure API Client Source: https://github.com/oceanengine/ad_open_sdk_go/blob/master/README.md Initialize the API client with a configuration, enable logging, set a custom HTTP client, add middleware, and modify client properties like log enablement, host, and default headers. ```golang func main() { configuration := config.NewConfiguration() configuration.LogEnable = true // 启用日志 configuration.HTTPClient = CustomeClient // 使用自定义 http client apiClient := ad_open_sdk_go.Init(configuration) apiClient.Use(xxxMiddleware) // 增加中间件 apiClient.SetLogEnable(true) // 初始化后修改是否启用日志 apiClient.SetHost("xxx.com") // 修改域名 apiClient.AddDefaultHeader("X-Debug-Header", "1") // 为每个请求增加默认 header apiClient.ApiClient.Cfg.xxx = xxx // 修改传入的config } ``` -------------------------------- ### Create Ad Promotion (v3.0) in Go Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Use this to create a new ad promotion, configuring creative assets and targeting strategies. Requires an access token, advertiser ID, and project ID. ```go package main import ( "context" "fmt" "io" ad_open_sdk_go "github.com/oceanengine/ad_open_sdk_go" "github.com/oceanengine/ad_open_sdk_go/config" . "github.com/oceanengine/ad_open_sdk_go/models" ) func main() { const accessToken = "your_access_token" ctx := context.Background() configuration := config.NewConfiguration() apiClient := ad_open_sdk_go.Init(configuration) apiClient.SetLogEnable(true) // 构建创建推广请求 request := PromotionCreateV30Request{ // AdvertiserId: 广告主ID // ProjectId: 项目ID // PromotionName: 推广名称 // 其他推广配置参数 } resp, httpRes, err := apiClient.PromotionCreateV30Api(). Post(ctx). AccessToken(accessToken). PromotionCreateV30Request(request). Execute() if err != nil { fmt.Printf("Error: %v\n", err) return } fmt.Printf("Created Promotion: %s\n", ToJsonString(resp)) resBytes, _ := io.ReadAll(httpRes.Body) fmt.Printf("Raw Response: %s\n", string(resBytes)) } ``` -------------------------------- ### SDK Package Structure Source: https://github.com/oceanengine/ad_open_sdk_go/blob/master/README.md Overview of the directory structure for the Marketing Go SDK. Key files include client.go for SDK initialization and api directory for API call logic. ```golang . ├── LICENSE ├── README.md ├── api │ ├── api_project_create_v30.go │ ├── api_xxx.go │ ├── client.go │ └── middleware.go ├── client.go ├── config │ └── configuration.go ├── examples │ ├── promotion_create_v30_example.go │ └── xxx_example.go ├── git_push.sh ├── go.mod ├── go.sum ├── middleware │ ├── auth.go │ ├── header.go │ └── log.go ├── models │ ├── model_promotion_create_v3_0_request.go │ ├── model_xxx_response.go │ └── utils.go └── test ``` -------------------------------- ### POST /open_api/v3.0/uni_project/create/ Source: https://github.com/oceanengine/ad_open_sdk_go/blob/master/README.md Creates a new unified project. ```APIDOC ## POST /open_api/v3.0/uni_project/create/ ### Description Creates a new project within the unified project management system. ### Method POST ### Endpoint /open_api/v3.0/uni_project/create/ ``` -------------------------------- ### Create Ad Project (v3.0) in Go Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Use this to create a new ad project with specified targeting and budget. Requires an access token, advertiser ID, and project name. ```go package main import ( "context" "fmt" "io" ad_open_sdk_go "github.com/oceanengine/ad_open_sdk_go" "github.com/oceanengine/ad_open_sdk_go/config" . "github.com/oceanengine/ad_open_sdk_go/models" ) func main() { const accessToken = "your_access_token" ctx := context.Background() configuration := config.NewConfiguration() apiClient := ad_open_sdk_go.Init(configuration) apiClient.SetLogEnable(true) // 构建创建项目请求 request := ProjectCreateV30Request{ // 设置项目参数 // AdvertiserId: 广告主ID // Name: 项目名称 // Budget: 预算 // 等其他必要参数 } resp, httpRes, err := apiClient.ProjectCreateV30Api(). Post(ctx). AccessToken(accessToken). ProjectCreateV30Request(request). Execute() if err != nil { fmt.Printf("Error: %v\n", err) return } fmt.Printf("Created Project: %s\n", ToJsonString(resp)) resBytes, _ := io.ReadAll(httpRes.Body) fmt.Printf("Raw Response: %s\n", string(resBytes)) } ``` -------------------------------- ### POST /api/v3/project/create Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Creates a new ad project with specified targeting and budget parameters. ```APIDOC ## POST /api/v3/project/create ### Description Creates a new ad project, setting targeting objectives and budget parameters. ### Method POST ### Endpoint /api/v3/project/create ### Parameters #### Request Body - **access_token** (string) - Required - Access token for authentication. - **advertiser_id** (integer) - Required - The ID of the advertiser. - **name** (string) - Required - The name of the project. - **budget** (number) - Required - The budget for the project. - **budget_mode** (string) - Optional - The budget mode (e.g., "BUDGET_MODE_DAY", "BUDGET_MODE_TOTAL"). - **budget_optimize_on** (string) - Optional - The budget optimization setting. - **campaign_type** (string) - Optional - The type of campaign. - **objective** (string) - Optional - The objective of the project. ### Request Example ```json { "access_token": "your_access_token", "advertiser_id": 1234567890, "name": "New Project", "budget": 10000.00, "budget_mode": "BUDGET_MODE_DAY", "objective": "CONVERSIONS" } ``` ### Response #### Success Response (200) - **data** (object) - Contains information about the created project. - **project_id** (integer) - The ID of the newly created project. - **name** (string) - The name of the project. - **message** (string) - Success message. - **code** (integer) - Response code. #### Response Example ```json { "data": { "project_id": 1002, "name": "New Project" }, "message": "success", "code": 0 } ``` ``` -------------------------------- ### POST /api/v3/promotion/create Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Creates an ad promotion, configuring creative assets and targeting strategies. ```APIDOC ## POST /api/v3/promotion/create ### Description Creates an ad promotion, configuring creative assets and targeting strategies. ### Method POST ### Endpoint /api/v3/promotion/create ### Parameters #### Request Body - **access_token** (string) - Required - Access token for authentication. - **advertiser_id** (integer) - Required - The ID of the advertiser. - **project_id** (integer) - Required - The ID of the project to which the promotion belongs. - **promotion_name** (string) - Required - The name of the promotion. - **budget** (number) - Optional - The budget for the promotion. - **budget_mode** (string) - Optional - The budget mode (e.g., "BUDGET_MODE_DAY", "BUDGET_MODE_TOTAL"). - **creative_ids** (array of integer) - Optional - IDs of the creative assets to be used. - **targeting** (object) - Optional - Targeting settings for the promotion. ### Request Example ```json { "access_token": "your_access_token", "advertiser_id": 1234567890, "project_id": 1002, "promotion_name": "Summer Promo", "budget": 2000.00, "budget_mode": "BUDGET_MODE_TOTAL", "creative_ids": [3001, 3002], "targeting": { "geo_locations": { "cities": [{"city_id": "10001"}] } } } ``` ### Response #### Success Response (200) - **data** (object) - Contains information about the created promotion. - **promotion_id** (integer) - The ID of the newly created promotion. - **promotion_name** (string) - The name of the promotion. - **message** (string) - Success message. - **code** (integer) - Response code. #### Response Example ```json { "data": { "promotion_id": 4001, "promotion_name": "Summer Promo" }, "message": "success", "code": 0 } ``` ``` -------------------------------- ### Configuration Struct Definition Source: https://github.com/oceanengine/ad_open_sdk_go/blob/master/README.md Defines the structure for SDK configuration, including host, scheme, headers, user agent, logging, and HTTP client. ```golang type Configuration struct { Host string `json:"host,omitempty" Scheme string `json:"scheme,omitempty" DefaultHeader map[string]string `json:"defaultHeader,omitempty" UserAgent string `json:"userAgent,omitempty" LogEnable bool `json:"log_enable,omitempty" HTTPClient *http.Client `json:"-" } ``` -------------------------------- ### Create Ad Campaign (v2) in Go Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Use this to create a new ad campaign, specifying its name, budget type, and landing page type. Requires an access token and advertiser ID. ```go package main import ( "context" "fmt" "io" ad_open_sdk_go "github.com/oceanengine/ad_open_sdk_go" "github.com/oceanengine/ad_open_sdk_go/config" . "github.com/oceanengine/ad_open_sdk_go/models" ) func main() { const accessToken = "your_access_token" ctx := context.Background() configuration := config.NewConfiguration() apiClient := ad_open_sdk_go.Init(configuration) apiClient.SetLogEnable(true) // 构建创建计划请求 request := CampaignCreateV2Request{ // AdvertiserId: 广告主ID // CampaignName: 计划名称 // BudgetMode: 预算类型 // LandingType: 推广目的 } resp, httpRes, err := apiClient.CampaignCreateV2Api(). Post(ctx). AccessToken(accessToken). CampaignCreateV2Request(request). Execute() if err != nil { fmt.Printf("Error: %v\n", err) return } fmt.Printf("Created Campaign: %s\n", ToJsonJsonString(resp)) resBytes, _ := io.ReadAll(httpRes.Body) fmt.Printf("Raw Response: %s\n", string(resBytes)) } ``` -------------------------------- ### POST /api/v2/campaign/create Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Creates a new ad campaign, setting campaign name, budget type, etc. ```APIDOC ## POST /api/v2/campaign/create ### Description Creates a new ad campaign, setting the campaign name, budget type, and other parameters. ### Method POST ### Endpoint /api/v2/campaign/create ### Parameters #### Request Body - **access_token** (string) - Required - Access token for authentication. - **advertiser_id** (integer) - Required - The ID of the advertiser. - **campaign_name** (string) - Required - The name of the campaign. - **budget_mode** (string) - Required - The budget mode (e.g., "BUDGET_MODE_DAY", "BUDGET_MODE_TOTAL"). - **budget** (number) - Required - The budget for the campaign. - **landing_type** (string) - Required - The landing type (e.g., "URL", "APP"). - **objective** (string) - Optional - The objective of the campaign. ### Request Example ```json { "access_token": "your_access_token", "advertiser_id": 1234567890, "campaign_name": "Summer Sale Campaign", "budget_mode": "BUDGET_MODE_DAY", "budget": 5000.00, "landing_type": "URL", "objective": "LINK_CLICKS" } ``` ### Response #### Success Response (200) - **data** (object) - Contains information about the created campaign. - **campaign_id** (integer) - The ID of the newly created campaign. - **campaign_name** (string) - The name of the campaign. - **message** (string) - Success message. - **code** (integer) - Response code. #### Response Example ```json { "data": { "campaign_id": 2001, "campaign_name": "Summer Sale Campaign" }, "message": "success", "code": 0 } ``` ``` -------------------------------- ### POST /open_api/v3.0/yuntu/audience_info/create/ Source: https://github.com/oceanengine/ad_open_sdk_go/blob/master/README.md Creates Yuntu audience information. ```APIDOC ## POST /open_api/v3.0/yuntu/audience_info/create/ ### Description Creates new audience information records in the Yuntu system. ### Method POST ### Endpoint /open_api/v3.0/yuntu/audience_info/create/ ``` -------------------------------- ### Retrieve Advertiser Information Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Fetch basic account details such as name, status, and balance for specified advertiser IDs. ```go package main import ( "context" "fmt" "io" ad_open_sdk_go "github.com/oceanengine/ad_open_sdk_go" "github.com/oceanengine/ad_open_sdk_go/config" . "github.com/oceanengine/ad_open_sdk_go/models" ) func main() { const accessToken = "your_access_token" ctx := context.Background() configuration := config.NewConfiguration() apiClient := ad_open_sdk_go.Init(configuration) apiClient.SetLogEnable(true) // 查询广告主信息 resp, httpRes, err := apiClient.AdvertiserInfoV2Api(). Get(ctx). AccessToken(accessToken). AdvertiserIds([]int64{1234567890, 9876543210}). // 广告主ID列表 Fields([]string{"id", "name", "status"}). // 返回字段 Execute() if err != nil { fmt.Printf("Error: %v\n", err) return } fmt.Printf("Advertiser Info: %s\n", ToJsonString(resp)) resBytes, _ := io.ReadAll(httpRes.Body) fmt.Printf("Raw Response: %s\n", string(resBytes)) } ``` -------------------------------- ### Implement Custom Middleware in Go Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Extend SDK functionality by creating custom middleware functions that wrap the api.Endpoint. Use apiClient.ApiClient.Use to register these middlewares for tasks like timing or retries. ```go package main import ( "context" "log" "net/http" "time" ad_open_sdk_go "github.com/oceanengine/ad_open_sdk_go" "github.com/oceanengine/ad_open_sdk_go/api" "github.com/oceanengine/ad_open_sdk_go/config" ) // 自定义计时中间件 func TimingMiddleware(next api.Endpoint) api.Endpoint { return func(ctx context.Context, req *http.Request) (resp *http.Response, err error) { start := time.Now() resp, err = next(ctx, req) duration := time.Since(start) log.Printf("Request to %s took %v\n", req.URL.Path, duration) return resp, err } } // 自定义重试中间件 func RetryMiddleware(maxRetries int) func(api.Endpoint) api.Endpoint { return func(next api.Endpoint) api.Endpoint { return func(ctx context.Context, req *http.Request) (resp *http.Response, err error) { for i := 0; i < maxRetries; i++ { resp, err = next(ctx, req) if err == nil && resp.StatusCode < 500 { return resp, err } log.Printf("Retry %d/%d for %s\n", i+1, maxRetries, req.URL.Path) time.Sleep(time.Second * time.Duration(i+1)) } return resp, err } } } func main() { configuration := config.NewConfiguration() apiClient := ad_open_sdk_go.Init(configuration) // 添加自定义中间件 apiClient.ApiClient.Use(TimingMiddleware) apiClient.ApiClient.Use(RetryMiddleware(3)) } ``` -------------------------------- ### POST /open_api/v3.0/tools/wechat_applet/update/ Source: https://github.com/oceanengine/ad_open_sdk_go/blob/master/README.md Updates WeChat applet information. ```APIDOC ## POST /open_api/v3.0/tools/wechat_applet/update/ ### Description Updates the configuration or details of a WeChat applet. ### Method POST ### Endpoint /open_api/v3.0/tools/wechat_applet/update/ ``` -------------------------------- ### POST /file/video/ad/v2 Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Uploads video advertising assets, supporting both direct file uploads and URL-based imports. ```APIDOC ## POST /file/video/ad/v2 ### Description Uploads video advertising assets, supporting file upload and URL methods. ### Method POST ### Parameters #### Request Body - **AdvertiserId** (int64) - Required - Advertiser ID - **Filename** (string) - Required - Name of the video file - **VideoSignature** (string) - Optional - MD5 signature of the video - **VideoUrl** (string) - Optional - URL of the video - **Labels** (array) - Optional - List of tags - **IsAigc** (boolean) - Optional - Whether the video is AIGC generated ``` -------------------------------- ### POST /open_api/v3.0/account/update/ Source: https://github.com/oceanengine/ad_open_sdk_go/blob/master/README.md Updates account information. ```APIDOC ## POST /open_api/v3.0/account/update/ ### Description Updates the details of an existing account. ### Method POST ### Endpoint /open_api/v3.0/account/update/ ``` -------------------------------- ### Create Qianchuan Ad (Go) Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Use this to create Qianchuan e-commerce ads for live stream and short video promotion. Ensure you have the correct access token and advertiser ID. ```go package main import ( "context" "fmt" "io" ad_open_sdk_go "github.com/oceanengine/ad_open_sdk_go" "github.com/oceanengine/ad_open_sdk_go/config" . "github.com/oceanengine/ad_open_sdk_go/models" ) func main() { const accessToken = "your_access_token" ctx := context.Background() configuration := config.NewConfiguration() apiClient := ad_open_sdk_go.Init(configuration) apiClient.SetLogEnable(true) // 构建千川广告创建请求 request := QianchuanAdCreateV10Request{ // AdvertiserId: 广告主ID // MarketingGoal: 营销目标 // 其他千川广告配置参数 } resp, httpRes, err := apiClient.QianchuanAdCreateV10Api(). Post(ctx). AccessToken(accessToken). QianchuanAdCreateV10Request(request). Execute() if err != nil { fmt.Printf("Error: %v\n", err) return } fmt.Printf("Created Qianchuan Ad: %s\n", ToJsonString(resp)) resBytes, _ := io.ReadAll(httpRes.Body) fmt.Printf("Raw Response: %s\n", string(resBytes)) } ``` -------------------------------- ### POST /qianchuan/ad/create/v1.0 Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Creates a new Qianchuan e-commerce advertisement, supporting both live stream and short video promotion formats. ```APIDOC ## POST /qianchuan/ad/create/v1.0 ### Description Creates a Qianchuan e-commerce advertisement, supporting live stream and short video promotion. ### Method POST ### Request Body - **AdvertiserId** (int64) - Required - Advertiser ID - **MarketingGoal** (string) - Required - Marketing goal ``` -------------------------------- ### POST /open_api/2/ad/update/bid/ Source: https://github.com/oceanengine/ad_open_sdk_go/blob/master/README.md Updates the bid for an advertisement. ```APIDOC ## POST /open_api/2/ad/update/bid/ ### Description Updates the bidding configuration for a specific advertisement. ### Method POST ### Endpoint /open_api/2/ad/update/bid/ ``` -------------------------------- ### Custom Middleware Interface Source: https://github.com/oceanengine/ad_open_sdk_go/blob/master/README.md Defines the interfaces for creating custom middleware in the SDK. Middleware can intercept and modify requests or responses. ```golang // Endpoint represent one method for calling from remote. type Endpoint func(ctx context.Context, req *http.Request) (resp *http.Response, err error) // Middleware deal with input Endpoint and output Endpoint. type Middleware func(Endpoint) Endpoint ``` -------------------------------- ### Obtain Access Token via OAuth2 Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Exchange an authorization code for an access token and refresh token to authenticate API requests. ```go package main import ( "context" "fmt" "io" ad_open_sdk_go "github.com/oceanengine/ad_open_sdk_go" "github.com/oceanengine/ad_open_sdk_go/config" . "github.com/oceanengine/ad_open_sdk_go/models" ) func main() { ctx := context.Background() configuration := config.NewConfiguration() apiClient := ad_open_sdk_go.Init(configuration) // 构建请求参数 var request Oauth2AccessTokenRequest request.AppId = PtrInt64(1234567890) // 应用 ID request.Secret = "your_app_secret" // 应用密钥 request.AuthCode = "authorization_code" // 授权码 // 调用获取 Token 接口 resp, httpRes, err := apiClient.Oauth2AccessTokenApi(). Post(ctx). Oauth2AccessTokenRequest(request). Execute() if err != nil { fmt.Printf("Error: %v\n", err) return } // 解析响应 fmt.Printf("Access Token: %s\n", ToJsonString(resp)) resBytes, _ := io.ReadAll(httpRes.Body) fmt.Printf("Raw Response: %s\n", string(resBytes)) } ``` -------------------------------- ### Refresh Access Token Source: https://context7.com/oceanengine/ad_open_sdk_go/llms.txt Use a refresh token to obtain a new access token when the current one expires. ```go package main import ( "context" "fmt" "io" ad_open_sdk_go "github.com/oceanengine/ad_open_sdk_go" "github.com/oceanengine/ad_open_sdk_go/config" . "github.com/oceanengine/ad_open_sdk_go/models" ) func main() { ctx := context.Background() configuration := config.NewConfiguration() apiClient := ad_open_sdk_go.Init(configuration) var request Oauth2RefreshTokenRequest request.AppId = PtrInt64(1234567890) request.Secret = "your_app_secret" request.RefreshToken = "your_refresh_token" resp, httpRes, err := apiClient.Oauth2RefreshTokenApi(). Post(ctx). Oauth2RefreshTokenRequest(request). Execute() if err != nil { fmt.Printf("Error: %v\n", err) return } fmt.Printf("New Access Token: %s\n", ToJsonString(resp)) resBytes, _ := io.ReadAll(httpRes.Body) fmt.Printf("Raw Response: %s\n", string(resBytes)) } ```