gometa

package
v1.2.142 Latest Latest
Warning

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

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

README

Meta(Facebook) Marketing Api

1 meta marking api

授权

2 meta audience api

授权

文档: https://developers.facebook.com/docs/audience-network/optimization/apis/FB-login-Reporting-API#getting-permissions

授权页面:

https://developers.facebook.com/docs/audience-network/optimization/apis/FB-login-Reporting-API#getting-permissions

2 meta 开发工具

Documentation

Index

Constants

View Source
const (
	BREAKDOWN_AD_SPACE        = "ad_space"        //按广告专区细分
	BREAKDOWN_COUNTRY         = "country"         //按国家/地区细分
	BREAKDOWN_DELIVERY_METHOD = "delivery_method" //如果指标来源于通过 Audience Network 竞价投放的广告,则按 standard 或 bidding 细分。仅适用于使用变现管理工具的发行商。
	BREAKDOWN_fAIL_REASON     = "fail_reason"     //仅适用于 fb_ad_network_no_fill 和 fb_ad_network_no_bid 指标。
	BREAKDOWN_PLACEMENT       = "placement"       //按版位编号细分。不能与 placement_name 一起使用。
	BREAKDOWN_PLACEMENT_NAME  = "placement_name"  //按版位编号和名称细分。不能与 placement 一起使用。
	BREAKDOWN_PLATFORM        = "platform"        //按平台细分。可以是 ios、android、mobile_web 或 instant_games。
	BREAKDOWN_PROPERTY        = "property"        //按资产编号细分
)

常用纬度 group by 数据 breakdowns breakdowns=['breakdown_1', 'breakdown_2',...]

View Source
const (
	FILTER_COUNTRY         = "country"         // country 以逗号分隔的双字母国家/地区缩写的清单
	FILTER_PLACEMENT       = "placement"       // placement  版位编号。限制:如果展示次数不足,值是 REDACTED。
	FILTER_DELIVERY_METHOD = "delivery_method" // delivery_method  standard 或 bidding
	FILTER_PLATFORM        = "platform"        // 可以是 ios(移动应用)、android(移动应用)、mobile_web 或 instant_games。
)

filters

View Source
const (
	AGGREGATION_PERIOD_HOUR  = "hour"
	AGGREGATION_PERIOD_DAY   = "day"
	AGGREGATION_PERIOD_TOTAL = "total"
)

aggregation_period=hour|day|total

View Source
const (
	Metrics_AD_NETWORK_BIDDING_BID_RATE = "fb_ad_network_bidding_bid_rate" // 竞价响应率
	Metrics_AD_NETWORK_BIDDING_REQUEST  = "fb_ad_network_bidding_request"  // 竞价请求数量
	Metrics_AD_NETWORK_BIDDING_RESPONSE = "fb_ad_network_bidding_response" // 竞价响应数量
	Metrics_AD_NETWORK_BIDDING_WIN_RATE = "fb_ad_network_bidding_win_rate" // 竞价工具赢得竞拍的比率
	Metrics_AD_NETWORK_CLICK            = "fb_ad_network_click"            // 点击量
	Metrics_AD_NETWORK_CPM              = "fb_ad_network_cpm"              // 有效千次展示费用 (eCPM)
	Metrics_AD_NETWORK_CTR              = "fb_ad_network_ctr"              // 预估点击率
	Metrics_AD_NETWORK_FILL_RATE        = "fb_ad_network_fill_rate"        // 广告请求填充率
	Metrics_AD_NETWORK_FILLED_REQUEST   = "fb_ad_network_filled_request"   // 填充的广告请求数量
	Metrics_AD_NETWORK_IMP              = "fb_ad_network_imp"              // 展示次数
	Metrics_AD_NETWORK_NO_BID           = "fb_ad_network_no_bid"           // 无响应竞价主因数量 仅适用于用作单个指标 fail_reason 细分条件的情况
	Metrics_AD_NETWORK_NO_FILL          = "fb_ad_network_no_fill"          // 无填充主因数量仅适用于用作单个指标 fail_reason 细分条件的情况
	Metrics_AD_NETWORK_REQUEST          = "fb_ad_network_request"          // 广告请求数量
	Metrics_AD_NETWORK_REVENUE          = "fb_ad_network_revenue"          // 预估收入
	Metrics_AD_NETWORK_SHOW_RATE        = "fb_ad_network_show_rate"        // 展示数除以填充请求数
)

指标

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"
)
View Source
const (
	ApiAdNetworkAnalytics = "/%s/adnetworkanalytics" // 变现广告网络分析
)

API

View Source
const (
	DOLLAR_UNIT = 1000000
)

1美元=1000000微分

Variables

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 AudienceData added in v1.2.136

type AudienceData struct {
	QueryId string `json:"query_id"`
	Results []struct {
		Time       string `json:"time"`
		Metric     string `json:"metric"`
		Breakdowns []struct {
			Key   string `json:"key"`
			Value string `json:"value"`
		} `json:"breakdowns"`
		Value string `json:"value"`
	} `json:"results"`
	OmittedResults []struct {
		Time       string `json:"time"`
		Metric     string `json:"metric"`
		Breakdowns []struct {
			Key   string `json:"key"`
			Value string `json:"value"`
		} `json:"breakdowns"`
	} `json:"omitted_results"`
}

ResponseData 数据

type AudienceDataRequest added in v1.2.136

type AudienceDataRequest struct {
	AggregationPeriod string `url:"aggregation_period"` //aggregation_period=hour|day|total 按 day(默认)、hour 或 total 汇总结果。限制:如要按小时汇总结果,您必须使用 since 和 until 查询至少 2 天内的结果。
	//Since 限制:
	//如要使用 Unix 时间戳,您的查询范围必须至少为 1 小时。
	//在同步请求中,您的请求范围最多为 8 天。
	//数据只会保留 540 天。如要请求的数据时间范围超过 $currentDate - 539 days,则系统不会返回更多数据。
	Since          string           `url:"since"` //since=YYYY-MM-DD 或 since=1548880485 查询的开始限制(始终包含边界值)。如果未添加此参数,默认为过去 7 天。
	Until          string           `url:"until"` //until=YYYY-MM-DD 或 until=1548880485+86400 查询的结束限制(默认不包含边界值,如果查询的汇总数据精确到小时,则包含边界值)
	Filter         []AudienceFilter `url:"filters"`
	Breakdowns     []string         `url:"breakdowns"`
	Metrics        []string         `url:"metrics"`
	Limit          int64            `url:"limit"`           //返回的行数。限制:同步请求的数量上限为 2,000。并限定每个指标获取 多少个响应
	OrderingColumn string           `url:"ordering_column"` //time|value,默认值为 time。
	OrderingType   string           `url:"ordering_type"`   //ascending|descending ,默认值为 descending。升序或降序。
	After          string           `url:"after"`           //下一页游标。
}

https://developers.facebook.com/docs/audience-network/optimization/report-api/guide-v2/ filters=[{'field':'country', 'operator':'in', 'values':['US', 'JP']}]

type AudienceDataResponse added in v1.2.136

type AudienceDataResponse struct {
	BaseResponse[[]AudienceData]
}

type AudienceFilter added in v1.2.136

type AudienceFilter struct {
	Field    string   `json:"field"`
	Operator string   `json:"operator"`
	Values   []string `json:"values"`
}

type AudienceReportResponse added in v1.2.136

type AudienceReportResponse struct {
	Items         []*AudienceResponseItem
	NextPageToken string
}

type AudienceResponseItem added in v1.2.136

type AudienceResponseItem struct {
	AppVersionName  string  `json:"app_version_name"`
	Platform        string  `json:"platform"`
	Format          string  `json:"format"`
	Date            string  `json:"date"`
	Hour            int64   `json:"hour"`
	AdUnit          string  `json:"ad_unit"`
	Country         string  `json:"country"`
	AdRequest       int64   `json:"ad_requests"`
	Clicks          int64   `json:"clicks"`
	Earnings        int64   `json:"earnings"` // 1美元=1000000微分,美分*10000. 这里如果 返回美分会损失精度
	Impressions     int64   `json:"impressions"`
	ImpressionCtr   float64 `json:"impression_ctr"`
	ImpressionRpm   float64 `json:"Impression_rpm"` //美元
	MatchedRequests int64   `json:"matched_requests"`
	MatchRate       float64 `json:"match_rate"`
	ShowRate        float64 `json:"show_rate"`
}

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"`
}

meta 通用返回数据结构

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 GoMeta added in v1.2.136

type GoMeta struct {
	Config Config
}

func Default added in v1.2.118

func Default() *GoMeta

func GetClient added in v1.2.118

func GetClient(names ...string) *GoMeta

func New added in v1.2.118

func New(config Config) *GoMeta

func (*GoMeta) AuthUrl added in v1.2.136

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

授权URL

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

func (*GoMeta) DecryptEcpms added in v1.2.136

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

func (*GoMeta) Exchange added in v1.2.136

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

获取token

func (*GoMeta) GetAudienceReport added in v1.2.136

func (m *GoMeta) GetAudienceReport(req *AudienceDataRequest, ID string) (*AudienceReportResponse, error)

func (*GoMeta) GetMarketAccountAdSetsOutline added in v1.2.136

func (m *GoMeta) GetMarketAccountAdSetsOutline(accountId string, startDate, endDate string, pageSize int) (*AllDataResponse, error)

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

func (*GoMeta) GetMarketAccountsByBusinessId added in v1.2.136

func (m *GoMeta) GetMarketAccountsByBusinessId(businessId string, pageSize int) (*AccountResponse, error)

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

func (*GoMeta) GetMarketAllDataByAccountId added in v1.2.136

func (m *GoMeta) GetMarketAllDataByAccountId(req *RequestData, accountId string) (*AllDataResponse, error)

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

func (*GoMeta) GetMarketDetailByDataId added in v1.2.136

func (m *GoMeta) GetMarketDetailByDataId(req *RequestData, dataId string) (*DataDetailResponse, error)

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

func (*GoMeta) GetMarketDetailsDataForCountry added in v1.2.136

func (m *GoMeta) GetMarketDetailsDataForCountry(outlineItem *AllDataItem, startDate, endDate string, pageSize int) (*DataDetailResponse, error)

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

func (*GoMeta) GetMetaAudienceReport added in v1.2.136

func (m *GoMeta) GetMetaAudienceReport(req *AudienceDataRequest, ID string) (*AudienceDataResponse, error)

<ID> 是您的 Meta 企业编号、资产编号或应用编号

func (*GoMeta) RefreshToken added in v1.2.136

func (m *GoMeta) RefreshToken() (*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
}

Jump to

Keyboard shortcuts

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