腾讯广告SDK 中间件
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)
}