96 lines
3.4 KiB
C#
96 lines
3.4 KiB
C#
namespace TikTokApi.Configuration;
|
|
|
|
/// <summary>
|
|
/// Root configuration for TikTok Marketing API integration.
|
|
/// Bind to the "TikTok" section in appsettings.json or environment variables.
|
|
///
|
|
/// TikTok auth model:
|
|
/// - Register as developer → create app → OAuth authorize → get access_token
|
|
/// - Access tokens do NOT expire unless the advertiser revokes authorization
|
|
/// - Token is passed via "Access-Token" HTTP header (not query param like Meta)
|
|
///
|
|
/// Agency model:
|
|
/// - Business Center (BC) is the parent entity (equivalent to Google MCC / Meta BM)
|
|
/// - BC owns advertiser accounts (ad accounts) created for clients
|
|
/// - BC API: /bc/advertiser/create, /bc/asset/get, /bc/transfer (fund management)
|
|
/// </summary>
|
|
public sealed class TikTokConfig
|
|
{
|
|
public const string SectionName = "TikTok";
|
|
|
|
/// <summary>
|
|
/// Enable/disable real API calls. When false, the provider returns emulated responses.
|
|
/// Override via: TikTok__EnableRealApi=true
|
|
/// </summary>
|
|
public bool EnableRealApi { get; set; } = false;
|
|
|
|
/// <summary>
|
|
/// TikTok Marketing API version (e.g. "v1.3").
|
|
/// Used in URL path: /open_api/v1.3/...
|
|
/// </summary>
|
|
public string ApiVersion { get; set; } = "v1.3";
|
|
|
|
/// <summary>
|
|
/// TikTok App ID from the Developer Portal (My Apps).
|
|
/// </summary>
|
|
public string AppId { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// TikTok App Secret from the Developer Portal.
|
|
/// Store in Key Vault; inject via environment variable in prod.
|
|
/// </summary>
|
|
public string AppSecret { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// Long-lived access token obtained via OAuth authorization flow.
|
|
/// Does NOT expire unless the advertiser revokes authorization.
|
|
/// Passed in "Access-Token" header on all API calls.
|
|
/// Store in Key Vault; inject via environment variable in prod.
|
|
/// </summary>
|
|
public string AccessToken { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// USIM's Business Center ID.
|
|
/// All client advertiser accounts are created under this BC.
|
|
/// Format: numeric string (e.g. "7123456789012345678")
|
|
/// </summary>
|
|
public string BusinessCenterId { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// Default advertiser ID for testing/sandbox.
|
|
/// Format: numeric string (e.g. "7123456789012345678")
|
|
/// </summary>
|
|
public string? DefaultAdvertiserId { get; set; }
|
|
|
|
/// <summary>
|
|
/// Request timeout in seconds for API calls.
|
|
/// </summary>
|
|
public int TimeoutSeconds { get; set; } = 60;
|
|
|
|
/// <summary>
|
|
/// TikTok Marketing API base URL.
|
|
/// Production: https://business-api.tiktok.com
|
|
/// Sandbox: https://sandbox-ads.tiktok.com
|
|
/// </summary>
|
|
public string ApiBaseUrl { get; set; } = "https://business-api.tiktok.com";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Per-request TikTok API context extracted from ProviderRequest.
|
|
/// </summary>
|
|
public sealed class TikTokApiContext
|
|
{
|
|
/// <summary>
|
|
/// TikTok advertiser (ad account) ID.
|
|
/// Derived from ProviderRequest.TenantId (accExternalAccountId).
|
|
/// Format: numeric string.
|
|
/// </summary>
|
|
public string AdvertiserId { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// Business Center ID that owns/manages the advertiser account.
|
|
/// Falls back to TikTokConfig.BusinessCenterId if not in request.
|
|
/// </summary>
|
|
public string? BusinessCenterId { get; set; }
|
|
}
|