meta

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 14 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 AggregateSourceError added in v0.2.0

type AggregateSourceError struct {
	Warnings []SourceWarning
}

AggregateSourceError is returned from ListPages when every attempted source produced an error and no pages were recovered. The caller can still inspect individual failures through Warnings.

func (*AggregateSourceError) Error added in v0.2.0

func (e *AggregateSourceError) Error() string

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 is the per-API-call page size passed to every underlying Graph
	// request (default 25).
	Limit int
	// All triggers exhaustive pagination of every source. Without it, each
	// source fetches only its first page and the results are aggregated.
	All bool
}

ListPagesParams configures the pages listing request.

type ListPagesResult

type ListPagesResult struct {
	Data     []Page          `json:"data"`
	Warnings []SourceWarning `json:"warnings,omitempty"`
	// HasNext is true when at least one source reported a next page. In
	// aggregated mode the caller cannot resume from a single cursor, so this
	// is purely informational.
	HasNext bool `json:"has_next"`
	// Cursor is retained for backward compatibility with the pre-aggregation
	// API shape and is always empty in the aggregated implementation.
	Cursor string `json:"cursor,omitempty"`
}

ListPagesResult contains the aggregated pages, any per-source warnings, and pagination state.

func ListPages

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

ListPages retrieves every Facebook Page the authenticated user can access by aggregating /me/accounts, /me/businesses → /{bm}/owned_pages, and /{bm}/client_pages. Per-source failures become Warnings; the call only errors when every attempted source failed.

type Page

type Page struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	// Category is empty for pages returned from /owned_pages and
	// /client_pages unless Meta includes it in the response.
	Category string `json:"category,omitempty"`
	// AccessToken is only present when the Page was reached via
	// /me/accounts. Business-Manager-sourced Pages do not expose a Page
	// access token on this endpoint.
	AccessToken string `json:"access_token,omitempty"`
	// Sources lists every route through which the user can reach this Page,
	// sorted alphabetically for deterministic output.
	Sources []PageSource `json:"sources"`
	// BusinessIDs lists every Business Manager through which the Page is
	// accessible, sorted lexicographically for deterministic output.
	BusinessIDs []string `json:"business_ids,omitempty"`
	// Tasks lists the permitted tasks on the Page, when Meta returns them.
	// The set varies by source; when a Page is reachable through multiple
	// sources the first non-empty set is retained.
	Tasks []string `json:"tasks,omitempty"`
}

Page represents a Facebook Page the authenticated user can access.

The same logical Page can be reachable through multiple sources (e.g. a direct role plus a Business Manager). In that case a single Page entry is returned with all sources unioned into Sources.

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 PageSource added in v0.2.0

type PageSource string

PageSource describes how the authenticated user has access to a Page.

const (
	// PageSourceDirect means the user has a direct role on the Page
	// (returned by GET /me/accounts).
	PageSourceDirect PageSource = "direct"
	// PageSourceBusinessOwned means the Page is owned by a Business Manager
	// the user is a member of (GET /{bm}/owned_pages).
	PageSourceBusinessOwned PageSource = "business_owned"
	// PageSourceBusinessClient means a Business Manager the user is a member
	// of has client access to the Page (GET /{bm}/client_pages).
	PageSourceBusinessClient PageSource = "business_client"
)

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 SourceWarning added in v0.2.0

type SourceWarning struct {
	// Source is a stable, machine-parseable identifier like "me/accounts" or
	// "business/581184769220955/owned_pages". No leading slash, no version.
	Source string `json:"source"`
	// Code is the Meta error code if the failure came from a Graph error.
	Code int `json:"code,omitempty"`
	// Message is a human-readable description of the failure.
	Message string `json:"message"`
}

SourceWarning describes a partial failure of one source during aggregation.

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 Video added in v0.1.1

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

Video is the canonical representation of a Meta video resource, shared by UploadVideo and GetVideoStatus. It is the single source of truth for the shape of a video returned to callers.

func GetVideoStatus

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

GetVideoStatus fetches the current metadata and encoding status of a video.

func UploadVideo

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

UploadVideo uploads a video file to the specified ad account and returns the full video record (id, title, status, length). Because Meta's upload endpoint only returns the new video's id, this function issues a follow-up GET against the same path used by GetVideoStatus so callers always receive a fully populated Video regardless of which code path produced it.

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.

Jump to

Keyboard shortcuts

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