gometa

package
v1.2.127 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

README

Meta(Facebook) Marketing Api

meta := gometa.Market{
    BaseApi:     "https://graph.facebook.com/v17.0",
    AccessToken: "token",
    StartDate:   "2024-01-01",
    EndDate:     "2024-01-01",
    PageSize:    200,
}
res, err := meta.GetAccountsByBusinessId("15738715864408601")
if err != nil {
    golog.WithTag("goMeta").Error(err.Error())
}

golog.WithTag("goMeta").Info(res)

Documentation

Index

Constants

View Source
const (
	OmniActivateApp  = "omni_activate_app"
	MobileAppInstall = "mobile_app_install"
	OmniPurchase     = "omni_purchase"
)

fb actions key

View Source
const (
	ApiAccount          = "/%s/client_ad_accounts"
	ApiAccountCampaigns = "/act_%s/campaigns"
	ApiAccountAdsets    = "/act_%s/adsets"
	ApiAccountAds       = "/act_%s/ads"
	ApiDataDetails      = "/%s/insights"
	ApiRefreshToken     = "/oauth/access_token"
)

Variables

This section is empty.

Functions

func DelClient added in v1.2.118

func DelClient(names ...string)

func Init added in v1.2.118

func Init(ctx context.Context, configs ...Config) (err error)

可以一次初始化多个实例或者 多次调用初始化多个实例

Types

type Account

type Account struct {
	Id            string `json:"id,optional"`
	AccountId     string `json:"account_id,optional"`
	Name          string `json:"name,optional"`
	AccountStatus int    `json:"account_status,optional"`
	Balance       string `json:"balance,optional"`
	Currency      string `json:"currency,optional"`
}

facebook 投放账户信息结构

type AccountResponse

type AccountResponse struct {
	BaseResponse[[]Account]
}

type AllDataItem

type AllDataItem struct {
	Name            string `json:"name,optional"`
	Status          string `json:"status,optional"`
	EffectiveStatus string `json:"effective_status,optional"`
	CampaignId      string `json:"campaign_id,optional"`
	AccountId       string `json:"account_id,optional"`
	AdsetId         string `json:"adset_id,optional"`
	Id              string `json:"id,optional"`
}

简要数据项(冗余:如:获取广告系列数据时 CampaignId,AdsetId 都为空 )

type AllDataResponse

type AllDataResponse struct {
	BaseResponse[[]AllDataItem]
}

type ApiAccessTokenRequest added in v1.2.118

type ApiAccessTokenRequest struct {
	RedirectUri  string `url:"redirect_uri"`
	ClientId     string `url:"client_id"`
	ClientSecret string `url:"client_secret"`
	Code         string `url:"code,optional"`
}

type ApiRefreshTokenRequest

type ApiRefreshTokenRequest struct {
	GrantType       string `url:"grant_type"`
	ClientId        string `url:"client_id"`
	ClientSecret    string `url:"client_secret"`
	FbExchangeToken string `url:"fb_exchange_token"`
}

type BaseResponse

type BaseResponse[T any] struct {
	Paging struct {
		Cursors struct {
			Before string `json:"before,optional"`
			After  string `json:"after,optional"`
		} `json:"cursors,optional"`
		Next string `json:"next,optional"`
	} `json:"paging,optional"`

	Data T `json:"data,optional"`
}

通用返回数据结构

type CampaignDetails

type CampaignDetails struct {
	AccountId          string `json:"account_id,optional"`
	CampaignId         string `json:"campaign_id,optional"`
	AdsetId            string `json:"adset_id,optional"`
	AdsetName          string `json:"adset_name,optional"`
	AdId               string `json:"ad_id,optional"`
	Impressions        string `json:"impressions,optional"`
	Cpm                string `json:"cpm,optional"`
	Cpc                string `json:"cpc,optional"`
	Spend              string `json:"spend,optional"`
	Clicks             string `json:"clicks,optional"`
	Conversions        string `json:"conversions,optional"`
	Objective          string `json:"objective,optional"`
	CostPerUniqueClick string `json:"cost_per_unique_click,optional"`
	AccountName        string `json:"account_name,optional"`
	Ctr                string `json:"ctr,optional"`
	DateStart          string `json:"date_start,optional"`
	DateStop           string `json:"date_stop,optional"`
	Country            string `json:"country,optional"`

	Actions []struct {
		ActionType string `json:"action_type,optional"`
		Value      string `json:"value,optional"`
	} `json:"actions,optional"`
}

func (*CampaignDetails) GetActionStat

func (f *CampaignDetails) GetActionStat(actionType string) int64

type CampaignStatus

type CampaignStatus string
const (
	ACTIVE   CampaignStatus = "ACTIVE"
	PAUSED   CampaignStatus = "PAUSED"
	DELETED  CampaignStatus = "DELETED"
	ARCHIVED CampaignStatus = "ARCHIVED"
)

type Config added in v1.2.118

type Config struct {
	Name string `yaml:"Name" json:"name,optional"`
	//请求参数
	ApiVersion  string `yaml:"ApiVersion" json:"apiVersion,optional"`
	AccessToken string `yaml:"AccessToken" json:"accessToken"`

	// 授权参数
	ClientId     string `yaml:"ClientId" json:"clientId"`
	ClientSecret string `yaml:"ClientSecret" json:"clientSecret"`
	RedirectUri  string `yaml:"RedirectUri" json:"redirectUri"`
	// contains filtered or unexported fields
}

type DataDetailResponse

type DataDetailResponse struct {
	BaseResponse[[]CampaignDetails]
}

type DetailsDataRequest

type DetailsDataRequest struct {
	RequestData
	TimeIncrement int    `url:"time_increment"`
	Timezone      string `url:"time_zone"`  //Asia/Shanghai
	Breakdowns    string `url:"breakdowns"` //['country'] 以国家纬度group by 查询
}

type EncryptedEcpmReq added in v1.2.119

type EncryptedEcpmReq struct {
	RequestId   string   `json:"request_id"`
	Ecpms       []string `json:"ecpms"`
	AccessToken string   `json:"access_token"`
	SyncApi     bool     `json:"sync_api"`
}

---------meta变现端--------------------------------

type EncryptedEcpmRes added in v1.2.119

type EncryptedEcpmRes struct {
	RequestId string `json:"request_id"`
	Success   struct {
		Value    float64 `json:"value"`
		Accuracy string  `json:"accuracy"`
	} `json:"success"`
	Error struct {
		Reason                 string `json:"reason"`
		Description            string `json:"description"`
		NoImpressionCount      int    `json:"no_impression_count"`
		InvalidImpressionCount int    `json:"invalid_impression_count"`
	} `json:"error"`
}

type Market

type Market struct {
	Config Config
}

func Default added in v1.2.118

func Default() *Market

func GetClient added in v1.2.118

func GetClient(names ...string) *Market

func New added in v1.2.118

func New(config Config) *Market

func (*Market) AuthUrl added in v1.2.118

func (c *Market) AuthUrl(scope string) string

授权URL

DOC: https://developers.facebook.com/docs/marketing-api/overview/authorization

func (*Market) DecryptEcpms added in v1.2.119

func (m *Market) DecryptEcpms(appId string, encryptedEcpms []string) (*EncryptedEcpmRes, error)

func (*Market) Exchange added in v1.2.118

func (c *Market) Exchange(authorizationCode string) (*TokenResponse, error)

获取token

func (*Market) GetAccountAdSetsOutline added in v1.2.118

func (m *Market) GetAccountAdSetsOutline(accountId string, startDate, endDate string, pageSize int) (*AllDataResponse, error)

概要数据加载,下一页数据 res.Paging.Cursors.After

func (*Market) GetAccountsByBusinessId

func (m *Market) GetAccountsByBusinessId(businessId string, pageSize int) (*AccountResponse, error)

某个商户下所有账号信息 账号余额,状态等等

func (*Market) GetAllDataByAccountId added in v1.2.118

func (m *Market) GetAllDataByAccountId(req *RequestData, accountId string) (*AllDataResponse, error)

all data -------------------------------

func (*Market) GetDetailByDataId added in v1.2.118

func (m *Market) GetDetailByDataId(req *RequestData, dataId string) (*DataDetailResponse, error)

根据数据类型获取某个详情,如:广告组详情 广告详情 -------------------------------

func (*Market) GetDetailsDataForCountry added in v1.2.118

func (m *Market) GetDetailsDataForCountry(outlineItem *AllDataItem, startDate, endDate string, pageSize int) (*DataDetailResponse, error)

某个计划或者广告组所有详情数据以 国家小时为纬度的数据 res.Paging.Cursors.After 通过这个参数重新请求下一页数据

func (*Market) RefreshToken

func (m *Market) RefreshToken(clientId string, clientSecret string) (*TokenResponse, error)

刷新token接口

type Paging

type Paging struct {
	Limit  int    `json:"limit,optional"`
	Before string `json:"before,optional"`
	After  string `json:"after,optional"`
}

type RequestAccessKes added in v1.2.118

type RequestAccessKes struct {
	AccessToken string `url:"access_token"`
}

type RequestData

type RequestData struct {
	Limit int `url:"limit"`
	//Before string `json:"before"`
	After string `url:"after"`

	AccessToken string `url:"access_token"`
	Fields      string `url:"fields"`

	DateStart string `url:"date_start"`
	DateStop  string `url:"date_stop"`
	TimeRange string `url:"time_range"` //DateStart And DateStop are here for query

	TimeIncrement int    `url:"time_increment"` // 1表示以天为单位
	Timezone      string `url:"time_zone"`      //日期时区Asia/Shanghai
	Breakdowns    string `url:"breakdowns"`     //['country'] 以国家纬度group by 查询
}

type TokenItem

type TokenItem struct {
	AccessToken string `json:"access_token,optional"`
	TokenType   string `json:"token_type,optional"`
	ExpiresIn   int    `json:"expires_in,optional"`

	Error struct {
		Message   string `json:"message,optional"`
		Type      string `json:"type,optional"`
		Code      int    `json:"code,optional"`
		FbtraceId string `json:"fbtrace_id,optional"`
	} `json:"error,optional"`
}

type TokenResponse

type TokenResponse struct {
	TokenItem
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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