91 lines
3.0 KiB
C#
91 lines
3.0 KiB
C#
namespace MetaApi.Configuration;
|
|
|
|
/// <summary>
|
|
/// Root configuration for Meta Marketing API integration.
|
|
/// Bind to the "Meta" section in appsettings.json or environment variables.
|
|
///
|
|
/// Meta uses System User tokens for server-to-server auth (no interactive OAuth flow).
|
|
/// These tokens don't expire if the System User remains active in Business Manager.
|
|
/// </summary>
|
|
public sealed class MetaConfig
|
|
{
|
|
public const string SectionName = "Meta";
|
|
|
|
/// <summary>
|
|
/// Enable/disable real API calls. When false, the provider returns emulated responses.
|
|
/// Override via: Meta__EnableRealApi=true
|
|
/// </summary>
|
|
public bool EnableRealApi { get; set; } = false;
|
|
|
|
/// <summary>
|
|
/// Graph API version (e.g. "v21.0").
|
|
/// Meta requires explicit versioning in all API URLs.
|
|
/// </summary>
|
|
public string ApiVersion { get; set; } = "v21.0";
|
|
|
|
/// <summary>
|
|
/// Meta App ID from the Developer Portal.
|
|
/// </summary>
|
|
public string AppId { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// Meta 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>
|
|
/// System User Access Token for server-to-server API calls.
|
|
/// Generated in Business Manager → System Users → Generate Token.
|
|
/// Unlike OAuth tokens, these don't expire unless revoked.
|
|
/// Store in Key Vault; inject via environment variable in prod.
|
|
/// </summary>
|
|
public string SystemUserToken { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// USIM's Business Manager ID.
|
|
/// All client ad accounts are created under this BM.
|
|
/// Format: numeric string (e.g. "123456789012345")
|
|
/// </summary>
|
|
public string BusinessManagerId { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// Default ad account ID for testing/sandbox.
|
|
/// Format: act_XXXXXXXXXXXXXXX (with "act_" prefix)
|
|
/// </summary>
|
|
public string? DefaultAdAccountId { get; set; }
|
|
|
|
/// <summary>
|
|
/// Request timeout in seconds for Graph API calls.
|
|
/// </summary>
|
|
public int TimeoutSeconds { get; set; } = 60;
|
|
|
|
/// <summary>
|
|
/// Graph API base URL. Override for sandbox/testing if needed.
|
|
/// </summary>
|
|
public string GraphApiBaseUrl { get; set; } = "https://graph.facebook.com";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Per-request Meta API context, populated from request and/or database.
|
|
/// </summary>
|
|
public sealed class MetaApiContext
|
|
{
|
|
/// <summary>
|
|
/// Target Meta ad account ID for this request.
|
|
/// Format: act_XXXXXXXXXXXXXXX (with "act_" prefix)
|
|
/// </summary>
|
|
public string AdAccountId { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// Business Manager ID that owns this ad account.
|
|
/// </summary>
|
|
public string? BusinessManagerId { get; set; }
|
|
|
|
/// <summary>
|
|
/// Optional override access token for a specific account.
|
|
/// If null, the platform System User token from config is used.
|
|
/// </summary>
|
|
public string? AccessToken { get; set; }
|
|
}
|