meta

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExitSuccess         = 0
	ExitAPIError        = 1
	ExitAuthError       = 2
	ExitValidationError = 3
	ExitConfigError     = 4
	ExitNetworkError    = 5
)

Variables

This section is empty.

Functions

func ClassifyError

func ClassifyError(err error) int

func DollarsToCents

func DollarsToCents(d float64) (int64, error)

Types

type Ad struct {
	ID       string     `json:"id"`
	Name     string     `json:"name"`
	AdSetID  string     `json:"adset_id"`
	Creative AdCreative `json:"creative"`
	Status   string     `json:"status"`
}

Ad represents a Meta ad returned by the API.

func CreateAd

func CreateAd(ctx context.Context, client Client, params CreateAdParams) (*Ad, error)

CreateAd creates a new ad under the given ad account.

type AdAccount

type AdAccount struct {
	ID            string `json:"id"`
	AccountID     string `json:"account_id"`
	Name          string `json:"name"`
	AccountStatus int    `json:"account_status"`
	Currency      string `json:"currency"`
	TimezoneName  string `json:"timezone_name"`
	AmountSpent   string `json:"amount_spent"`
	Balance       string `json:"balance"`
}

AdAccount represents a Meta ad account.

type AdCreative

type AdCreative struct {
	ID string `json:"id"`
}

AdCreative holds the creative reference within an ad.

type AdSet

type AdSet struct {
	ID             string `json:"id"`
	Name           string `json:"name"`
	CampaignID     string `json:"campaign_id"`
	Status         string `json:"status"`
	DailyBudget    string `json:"daily_budget,omitempty"`
	LifetimeBudget string `json:"lifetime_budget,omitempty"`
}

AdSet represents a Meta ad set returned by the API.

func CreateAdSet

func CreateAdSet(ctx context.Context, client Client, params CreateAdSetParams) (*AdSet, error)

CreateAdSet creates a new ad set under the given ad account.

type AuthApp

type AuthApp struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

AuthApp represents the application associated with the access token.

type AuthStatusResult

type AuthStatusResult struct {
	Valid       bool     `json:"valid"`
	User        AuthUser `json:"user"`
	App         AuthApp  `json:"app"`
	Permissions []string `json:"permissions"`
	ExpiresAt   string   `json:"expires_at"`
	Scopes      []string `json:"scopes"`
}

AuthStatusResult contains the result of validating an access token.

func AuthStatus

func AuthStatus(ctx context.Context, client Client) (*AuthStatusResult, error)

AuthStatus validates the current access token by calling /me, /me/permissions, and /debug_token to populate the full AuthStatusResult including app identity and token expiry. The client's token is used implicitly (injected by the transport layer).

type AuthUser

type AuthUser struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

AuthUser represents the authenticated user's identity.

type Campaign

type Campaign struct {
	ID             string `json:"id"`
	Name           string `json:"name"`
	Objective      string `json:"objective"`
	Status         string `json:"status"`
	DailyBudget    string `json:"daily_budget,omitempty"`
	LifetimeBudget string `json:"lifetime_budget,omitempty"`
}

Campaign represents a Meta campaign returned by the API.

func CreateCampaign

func CreateCampaign(ctx context.Context, client Client, params CreateCampaignParams) (*Campaign, error)

CreateCampaign creates a new campaign under the given ad account.

type Client

type Client interface {
	Get(ctx context.Context, path string, params url.Values) (*Response, error)
	Post(ctx context.Context, path string, params map[string]string) (*Response, error)
	Upload(ctx context.Context, path string, file io.Reader, filename string, size int64, params map[string]string) (*Response, error)
	Paginate(ctx context.Context, path string, params url.Values) *PageIterator
	SetDryRun(v bool)
	SetVerbose(v bool)
}

type CreateAdParams

type CreateAdParams struct {
	AccountID  string
	Name       string
	AdSetID    string
	CreativeID string
	Status     string // default: PAUSED
}

CreateAdParams holds the input for creating a Meta ad.

type CreateAdSetParams

type CreateAdSetParams struct {
	AccountID           string
	Name                string
	CampaignID          string
	DailyBudgetCents    int64
	LifetimeBudgetCents int64
	OptimizationGoal    string
	BillingEvent        string // default: IMPRESSIONS
	BidAmountCents      int64
	Countries           []string // required, non-empty
	AgeMin              int      // default: 18
	AgeMax              int      // default: 65
	Genders             []int    // default: [1,2]
	Interests           []string // interest IDs
	Behaviors           []string
	CustomAudiences     []string
	ExcludedCountries   []string
	PublisherPlatforms  []string
	PixelID             string
	CustomEventType     string
	StartTime           string
	EndTime             string
	AdvantageAudience   bool   // default: false (explicit targeting)
	Status              string // default: PAUSED
}

CreateAdSetParams holds the input for creating a Meta ad set.

type CreateCampaignParams

type CreateCampaignParams struct {
	AccountID           string
	Name                string
	Objective           string // OUTCOME_SALES, OUTCOME_TRAFFIC, etc.
	DailyBudgetCents    int64  // mutually exclusive with LifetimeBudgetCents
	LifetimeBudgetCents int64
	BidStrategy         string // default: LOWEST_COST_WITHOUT_CAP
	Status              string // default: PAUSED
	SpecialAdCategory   string // default: NONE
}

CreateCampaignParams holds the input for creating a Meta campaign.

type CreateCreativeParams

type CreateCreativeParams struct {
	AccountID          string
	Name               string
	PageID             string // required
	VideoID            string // one of VideoID/ImageHash/ImageURL required
	ImageHash          string
	ImageURL           string
	Message            string // required
	Headline           string
	Description        string
	CTA                string // default: SHOP_NOW
	Link               string // required
	InstagramAccountID string
}

CreateCreativeParams holds the input for creating a Meta ad creative.

type Creative

type Creative struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

Creative represents a Meta ad creative returned by the API.

func CreateCreative

func CreateCreative(ctx context.Context, client Client, params CreateCreativeParams) (*Creative, error)

CreateCreative creates a new ad creative under the given ad account.

type GraphError

type GraphError struct {
	Message     string `json:"message"`
	Type        string `json:"type"`
	Code        int    `json:"code"`
	Subcode     int    `json:"error_subcode"`
	TraceID     string `json:"fbtrace_id"`
	IsRetryable bool
}

func ParseGraphError

func ParseGraphError(body []byte) *GraphError

func (*GraphError) Error

func (e *GraphError) Error() string

type ListAccountsParams

type ListAccountsParams struct {
	Limit int
}

ListAccountsParams configures the ad accounts listing request.

type ListAccountsResult

type ListAccountsResult struct {
	Data    []AdAccount `json:"data"`
	HasNext bool        `json:"has_next"`
	Cursor  string      `json:"cursor"`
}

ListAccountsResult contains ad accounts and pagination state.

func ListAccounts

func ListAccounts(ctx context.Context, client Client, params ListAccountsParams) (*ListAccountsResult, error)

ListAccounts retrieves ad accounts accessible by the authenticated user. GET /me/adaccounts?fields=account_id,name,account_status,currency,timezone_name,amount_spent,balance&limit=N

type ListPagesParams

type ListPagesParams struct {
	Limit int
}

ListPagesParams configures the pages listing request.

type ListPagesResult

type ListPagesResult struct {
	Data    []Page `json:"data"`
	HasNext bool   `json:"has_next"`
	Cursor  string `json:"cursor"`
}

ListPagesResult contains pages and pagination state.

func ListPages

func ListPages(ctx context.Context, client Client, params ListPagesParams) (*ListPagesResult, error)

ListPages retrieves Facebook Pages the authenticated user manages. GET /me/accounts?fields=id,name,category,access_token&limit=N

type Page

type Page struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Category    string `json:"category"`
	AccessToken string `json:"access_token"`
}

Page represents a Facebook Page managed by the authenticated user.

type PageIterator

type PageIterator struct {
	// contains filtered or unexported fields
}

func NewPageIterator

func NewPageIterator(client Client, path string, params url.Values) *PageIterator

func (*PageIterator) Err

func (it *PageIterator) Err() error

func (*PageIterator) Next

func (it *PageIterator) Next(ctx context.Context) bool

func (*PageIterator) Page

func (it *PageIterator) Page() (*Response, error)

type Response

type Response struct {
	Body       []byte
	StatusCode int
	Headers    http.Header
}

type SearchTargetingParams

type SearchTargetingParams struct {
	AccountID string
	Type      string
	Query     string
	Limit     int
}

SearchTargetingParams contains the parameters for searching targeting options.

type SearchTargetingResult

type SearchTargetingResult struct {
	Data []TargetingSuggestion `json:"data"`
}

SearchTargetingResult contains the list of targeting suggestions from the API.

func SearchTargeting

func SearchTargeting(ctx context.Context, client Client, params SearchTargetingParams) (*SearchTargetingResult, error)

SearchTargeting searches for targeting options (interests, behaviors, demographics, etc.).

type TargetingSuggestion

type TargetingSuggestion struct {
	ID                     string   `json:"id"`
	Name                   string   `json:"name"`
	Type                   string   `json:"type"`
	AudienceSizeLowerBound int64    `json:"audience_size_lower_bound"`
	AudienceSizeUpperBound int64    `json:"audience_size_upper_bound"`
	Path                   []string `json:"path"`
}

TargetingSuggestion represents a single targeting option returned by the API.

type UploadVideoParams

type UploadVideoParams struct {
	AccountID string
	File      io.Reader
	Filename  string
	FileSize  int64
	Title     string
}

UploadVideoParams contains the parameters for uploading a video to an ad account.

type UploadVideoResult

type UploadVideoResult struct {
	ID           string `json:"id"`
	Title        string `json:"title"`
	UploadStatus string `json:"upload_status"`
}

UploadVideoResult contains the response from a video upload operation.

func UploadVideo

func UploadVideo(ctx context.Context, client Client, params UploadVideoParams) (*UploadVideoResult, error)

UploadVideo uploads a video file to the specified ad account.

type VideoStatus

type VideoStatus struct {
	VideoStatus        string `json:"video_status"`
	ProcessingProgress int    `json:"processing_progress"`
}

VideoStatus represents the encoding status of a video.

type VideoStatusParams

type VideoStatusParams struct {
	VideoID string
}

VideoStatusParams contains the parameters for checking video encoding status.

type VideoStatusResult

type VideoStatusResult struct {
	ID     string      `json:"id"`
	Title  string      `json:"title"`
	Status VideoStatus `json:"status"`
	Length float64     `json:"length"`
}

VideoStatusResult contains the response from a video status check.

func GetVideoStatus

func GetVideoStatus(ctx context.Context, client Client, params VideoStatusParams) (*VideoStatusResult, error)

GetVideoStatus checks the encoding status of a previously uploaded video.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL