goadmob

package
v1.2.110 Latest Latest
Warning

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

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

README

Google admob data Api

Admob API 授权

官方调试平台(授权 获取Token 访问)

https://developers.google.com/oauthplayground/
1 把 redirect_uri 改为自己的服务器地址
https://accounts.google.com/o/oauth2/v2/auth?redirect_uri=https%3A%2F%2Fbangbox.jidianle.cc&prompt=consent&response_type=code&client_id=273488495628-a56cdd6vrnkm5i5ors5vl2bmrj3rh622.apps.googleusercontent.com&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadmob.readonly+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadmob.report&access_type=offline
跳转后选择权限 需要授权账号
2 授权后会返回 code
3 获取AccessToken 和 RefreshToken
4 需求

https://admob.googleapis.com/v1/accounts/pub-4328354313035484/networkReport:generate

curl -X POST \
      https://admob.googleapis.com/v1/accounts/pub-4328354313035484/networkReport:generate \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer ya29.a0AeDClZDwt6OuYT2sn6WWkyYnO8rZlLDjEB5O0K5f_K4Bf82FERBrbXrkrqHk4fLF3PX9BXfPy5vxoPT4h22mh9UI7EhD3R_7exG4aQNgKf-uFX_54UjcH4evy57A6HKSnwBnntcoTA4TztQPv2B5X7ul63uWVII2r854XIwLkwaCgYKASwSARISFQHGX2Mi2sMVueB5UvyB5NF7mxfidg0177" \
      -H "X-Goog-AuthUser": "0" \
      --data @- << EOF
{
 "report_spec": {
   "date_range": {
     "start_date": {"year": 2024, "month": 4, "day": 1},
     "end_date": {"year": 2024, "month": 4, "day": 2}
   },
   "dimensions": ["DATE"],
   "metrics": ["CLICKS", "AD_REQUESTS", "IMPRESSIONS", "ESTIMATED_EARNINGS"],
   "dimension_filters": [{"dimension": "COUNTRY", "matches_any": {"values": ["US"]}}],
   "sort_conditions": [{"metric":"CLICKS", order: "DESCENDING"}],
   "localization_settings": {"currency_code": "USD", "language_code": "en-US"}
 }
}
EOF
[ {
  "header" : {
    "dateRange" : {
      "startDate" : {
        "year" : 2024,
        "month" : 8,
        "day" : 20
      },
      "endDate" : {
        "year" : 2024,
        "month" : 8,
        "day" : 21
      }
    },
    "localizationSettings" : {
      "currencyCode" : "USD"
    }
  }
}, {
  "row" : {
    "dimensionValues" : {
      "DATE" : {
        "value" : "20240820"
      },
      "APP" : {
        "value" : "ca-app-pub-4328354313035484~1283901700",
        "displayLabel" : "JumpJumpVPN- Fast & Secure VPN"
      },
      "COUNTRY" : {
        "value" : "AD"
      }
    },
    "metricValues" : {
      "CLICKS" : {
        "integerValue" : "0"
      },
      "ESTIMATED_EARNINGS" : {
        "microsValue" : "238"
      }
    }
  }
}, {
  "row" : {
    "dimensionValues" : {
      "DATE" : {
        "value" : "20240820"
      },
      "APP" : {
        "value" : "ca-app-pub-4328354313035484~1283901700",
        "displayLabel" : "JumpJumpVPN- Fast & Secure VPN"
      },
      "COUNTRY" : {
        "value" : "AE"
      }
    },
    "metricValues" : {
      "CLICKS" : {
        "integerValue" : "22"
      },
      "ESTIMATED_EARNINGS" : {
        "microsValue" : "1427375"
      }
    }
  }
}, {
  "row" : {
    "dimensionValues" : {
      "DATE" : {
        "value" : "20240820"
      },
      "APP" : {
        "value" : "ca-app-pub-4328354313035484~2152486667",
        "displayLabel" : "VPN - biubiuVPN Fast & Secure"
      },
      "COUNTRY" : {
        "value" : "AE"
      }
    },
    "metricValues" : {
      "CLICKS" : {
        "integerValue" : "223"
      },
      "ESTIMATED_EARNINGS" : {
        "microsValue" : "7850960"
      }
    }
  }
}, {
  "row" : {
    "dimensionValues" : {
      "DATE" : {
        "value" : "20240820"
      },
      "APP" : {
        "value" : "ca-app-pub-4328354313035484~7713423190",
        "displayLabel" : "biubiuVPN : VPN"
      },
      "COUNTRY" : {
        "value" : "AE"
      }
    },
    "metricValues" : {
      "CLICKS" : {
        "integerValue" : "71"
      },
      "ESTIMATED_EARNINGS" : {
        "microsValue" : "4050666"
      }
    }
  }
}, {
  "row" : {
    "dimensionValues" : {
      "DATE" : {
        "value" : "20240820"
      },
      "APP" : {
        "value" : "ca-app-pub-4328354313035484~8600583746",
        "displayLabel" : "JumpJumpVPN- Fast & Secure VPN"
      },
      "COUNTRY" : {
        "value" : "AE"
      }
    },
    "metricValues" : {
      "CLICKS" : {
        "integerValue" : "259"
      },
      "ESTIMATED_EARNINGS" : {
        "microsValue" : "6430629"
      }
    }
  }
}, {
  "row" : {
    "dimensionValues" : {
      "DATE" : {
        "value" : "20240820"
      },
      "APP" : {
        "value" : "ca-app-pub-4328354313035484~1283901700",
        "displayLabel" : "JumpJumpVPN- Fast & Secure VPN"
      },
      "COUNTRY" : {
        "value" : "AF"
      }
    },
    "metricValues" : {
      "CLICKS" : {
        "integerValue" : "0"
      },
      "ESTIMATED_EARNINGS" : {
        "microsValue" : "3914"
      }
    }
  }
}, {
  "row" : {
    "dimensionValues" : {
      "DATE" : {
        "value" : "20240820"
      },
      "APP" : {
        "value" : "ca-app-pub-4328354313035484~2152486667",
        "displayLabel" : "VPN - biubiuVPN Fast & Secure"
      },
      "COUNTRY" : {
        "value" : "AF"
      }
    },
    "metricValues" : {
      "CLICKS" : {
        "integerValue" : "13"
      },
      "ESTIMATED_EARNINGS" : {
        "microsValue" : "127095"
      }
    }
  }
}, {
  "row" : {
    "dimensionValues" : {
      "DATE" : {
        "value" : "20240820"
      },
      "APP" : {
        "value" : "ca-app-pub-4328354313035484~7713423190",
        "displayLabel" : "biubiuVPN : VPN"
      },
      "COUNTRY" : {
        "value" : "AF"
      }
    },
    "metricValues" : {
      "CLICKS" : {
        "integerValue" : "2"
      },
      "ESTIMATED_EARNINGS" : {
        "microsValue" : "60361"
      }
    }
  }
}, {
  "row" : {
    "dimensionValues" : {
      "DATE" : {
        "value" : "20240820"
      },
      "APP" : {
        "value" : "ca-app-pub-4328354313035484~8600583746",
        "displayLabel" : "JumpJumpVPN- Fast & Secure VPN"
      },
      "COUNTRY" : {
        "value" : "AF"
      }
    },
    "metricValues" : {
      "CLICKS" : {
        "integerValue" : "8"
      },
      "ESTIMATED_EARNINGS" : {
        "microsValue" : "67432"
      }
    }
  }
}, {
  "row" : {
    "dimensionValues" : {
      "DATE" : {
        "value" : "20240820"
      },
      "APP" : {
        "value" : "ca-app-pub-4328354313035484~2152486667",
        "displayLabel" : "VPN - biubiuVPN Fast & Secure"
      },
      "COUNTRY" : {
        "value" : "AL"
      }
    },
    "metricValues" : {
      "CLICKS" : {
        "integerValue" : "0"
      },
      "ESTIMATED_EARNINGS" : {
        "microsValue" : "341"
      }
    }
  }
}, {
  "footer" : {
    "matchingRowCount" : "846"
  }
} ]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DelClient

func DelClient(names ...string)

func Init

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

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

Types

type Config

type Config struct {
	Name         string `yaml:"Name" json:"name,optional"`
	AccountId    string `yaml:"AccountId" json:"accountId,optional"`
	ClientId     string `yaml:"ClientId" json:"clientId"`
	ClientSecret string `yaml:"ClientSecret" json:"clientSecret"`
	RedirectUrl  string `yaml:"RedirectUrl" json:"redirectUrl"`
	State        string `yaml:"State" json:"state"`

	AccessToken  string `yaml:"AccessToken" json:"accessToken"`
	RefreshToken string `yaml:"RefreshToken" json:"refreshToken"`
}

type GoAdmob

type GoAdmob struct {
	Config       Config
	AuthConfig   oauth2.Config
	AdmobService *admob.Service
	Token        *oauth2.Token
	// contains filtered or unexported fields
}

accessToken 会在60分钟后过期

func Default

func Default() *GoAdmob

func GetClient

func GetClient(names ...string) *GoAdmob

func New

func New(ctx context.Context, config Config) (*GoAdmob, error)

每次调用时都需要调用这个方法

func (*GoAdmob) AuthUrl

func (c *GoAdmob) AuthUrl() string

授权admobURL

func (*GoAdmob) Exchange

func (c *GoAdmob) Exchange(ctx context.Context, code string) (*oauth2.Token, error)

获取token

func (*GoAdmob) GetAdUnits

func (c *GoAdmob) GetAdUnits() (*admob.ListAdUnitsResponse, error)

获取当前appId下所有的广告信息

func (*GoAdmob) GetApps

func (c *GoAdmob) GetApps() (*admob.ListAppsResponse, error)

获取账号下所有APP信息

func (*GoAdmob) GetReport

func (c *GoAdmob) GetReport(req *ReportReq) ([]*ResponseItem, error)

dimensions 指定查询维度,如:[]string{"DATE", "APP", "COUNTRY"}

SELECT DATE, APP, COUNTRY, CLICKS, ESTIMATED_EARNINGS FROM NETWORK_REPORT WHERE DATE >= '2021-09-01' AND DATE <= '2021-09-30'

AND COUNTRY IN ('US', 'CN')

GROUP BY DATE, APP, COUNTRY ORDER BY APP ASC, CLICKS DESC;

func (*GoAdmob) Refresh

func (o *GoAdmob) Refresh() error

RefreshToken and AdmobService admon token 有效期为60分钟,所有每次请求数据刷新下token

func (*GoAdmob) RefreshToken

func (c *GoAdmob) RefreshToken() error

刷新token

type ReportReq added in v1.2.109

type ReportReq struct {
	Dimensions      []string //查询维度列表
	AdUnits         []string //广告位
	AdFormats       []string //原生、横幅、插屏、开屏、激励视频
	Platforms       []string //应用的移动操作系统平台(例如“Android”或“iOS”)。
	AppVersionNames []string //对于 Android,应用版本名称可以在 PackageInfo 中的 versionName 中找到。对于 iOS,可以在 CFBundleShortVersionString 中找到应用版本名称。警告:该维度与 ESTIMATED_EARNINGS 和 OBSERVED_ECPM 指标不兼容。
	MaxReportRows   int64    //最大返回数量
	Metrics         []string //查询字段、注意:这里的查询字段在不同的纬度下有互斥情况

	StartDate admob.Date
	EndDate   admob.Date
}

type ResponseItem added in v1.2.110

type ResponseItem struct {
	Date            string
	AdUnit          string
	Country         string
	AdRequest       int64
	Clicks          int64
	Earnings        int64 //美分
	Impressions     int64
	ImpressionCtr   float64
	ImpressionRpm   int64 //美分
	MatchedRequests int64
	MatchRate       float64
	ShowRate        float64
}

Jump to

Keyboard shortcuts

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