Giter Site home page Giter Site logo

google-ads-pb's Introduction

Google Ads API Client Library for Golang

Go GoDoc Go Report Card License

This library provides a Golang client for the Google Ads API. It's fully generated from the googleapis repository. More information on the generation process can be found here.

Although this project isn't official, we deem it as low-risk due to its maturity and our two years of using it in production. However, always consult the sunset schedule of the Google Ads API.

Features

  • Full support for Google Ads API.
  • Source code generated from the official googleapis repository.
  • Support for GRPC and HTTP calls using protojson.
  • Although we won't regularly update this based on the official repository, we continually maintain it. Update frequency depends on our needs but usually occurs a month after the official release.

Version support

google-ads-pb Google Ads API Sunset date
v1.7.0 v16 January 2025
v1.6.0 v15 September 2024
v1.5.1 v14.1 June 5, 2024
v1.5.0 v14 June 5, 2024
v1.4.1 v13.1 Deprecated
v1.4.0 v13 Deprecated
v1.3.1 v12 Deprecated
v1.2.1 v11.1 Deprecated
v1.2.0 v11 Deprecated
v1.1.1 v10 Deprecated

Requirements

Installation

$ go get github.com/shenzhencenter/google-ads-pb

Getting started

  1. Set your environment variables.
$ export ACCESS_TOKEN=<your access token>
$ export DEVELOPER_TOKEN=<your developer token>
$ export CUSTOMER_ID=<your customer id>
  1. Establish a GRPC connection.
ctx := context.Background()

headers := metadata.Pairs(
  "authorization", "Bearer "+os.Getenv("ACCESS_TOKEN"),
  "developer-token", os.Getenv("DEVELOPER_TOKEN"),
  "login-customer-id", os.Getenv("CUSTOMER_ID"),
)
ctx = metadata.NewOutgoingContext(ctx, headers)

cred := grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, ""))
conn, err := grpc.Dial("googleads.googleapis.com:443", cred)
if err != nil {
  panic(err)
}
defer conn.Close()
  1. Start making calls.
customerServiceClient := services.NewCustomerServiceClient(conn)
accessibleCustomers, err := customerServiceClient.ListAccessibleCustomers(
  ctx, 
  &services.ListAccessibleCustomersRequest{},
)
if err != nil {
  panic(err)
}

for _, customer := range accessibleCustomers.ResourceNames {
  fmt.Println("ResourceName: " + customer)
}

You can also make HTTP calls using protojson, though it isn't recommended.

req := services.ListAccessibleCustomersRequest{}
requestBody, err := protojson.Marshal(&req)
if err != nil {
  panic(err)
}
request, err := http.NewRequest("GET", "https://googleads.googleapis.com/v15/customers:listAccessibleCustomers", bytes.NewBuffer(requestBody))
if err != nil {
  panic(err)
}
header := make(http.Header)
header.Set("content-type", "application/json")
header.Set("authorization", os.Getenv("ACCESS_TOKEN"))
header.Set("developer-token", os.Getenv("DEVELOPER_TOKEN"))
request.Header = header
client := &http.Client{}
response, err := client.Do(request)
if err != nil {
  panic(err)
}
defer response.Body.Close()
var responseBody []byte
if responseBody, err = io.ReadAll(response.Body); err != nil {
  panic(err)
}
listAccessibleCustomersResponse := new(services.ListAccessibleCustomersResponse)
if err := protojson.Unmarshal(response, listAccessibleCustomersResponse); err != nil {
  panic(err)
}
for _, customer := range listAccessibleCustomersResponse.ResourceNames {
  fmt.Println("ResourceName: " + customer)
}

Examples

See clients/internal/snippets.

Related

Here are some related projects

Contributing

As this project is fully protoc-generated, we aren't accepting pull requests. However, we value your feedback and suggestions, so feel free to open an issue.

google-ads-pb's People

Contributors

xnkjj avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.