/tad-middlewares

腾讯广告SDK 中间件

Primary LanguageGoApache License 2.0Apache-2.0

tad-middlewares

腾讯广告SDK 中间件

Go Reference Go goreleaser GitHub go.mod Go version of a Go module GoReportCard GitHub license GitHub release

Opentelementry Middleware

import (
  "github.com/tencentad/marketing-api-go-sdk/pkg/ads/v3"
  "github.com/tencentad/marketing-api-go-sdk/pkg/config/v3"
)
func main() {
  tads:= ads.Init(&config.SDKConfig{})
  mw := tadmw.NewOtelMiddlware(clt, "")
  tads.AppendMiddleware(mw)
  // your client id
	clientId := int64(0)
	clientSecret := "your client secret"
	grantType := "authorization_code"
	oauthTokenOpts := &api.OauthTokenOpts{
		AuthorizationCode: optional.NewString("your authorization code"),
		RedirectUri: optional.NewString("your authorization code"),
	}
	ctx := *tads.Ctx
	// oauth/token接口即对应Oauth().Token()方法
	response, _, err := tads.Oauth().Token(ctx, clientId, clientSecret, grantType, oauthTokenOpts)

	if err != nil {
		if resErr, ok := err.(errors.ResponseError); ok {
			errStr, _ := json.Marshal(resErr)
			// TODO for api error
			fmt.Println("Response error:", string(errStr))
		} else {
			// TODO for other error
			fmt.Println("Error:", err)
		}
	}
	tads.SetAccessToken(response.AccessToken)
}