Skip to content

Repository files navigation

Google Ads API Client Library for Golang

GoGoDocGo Report CardLicense

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-pbGoogle Ads APISunset date
v1.4.0v22End of October 2026
Skippedv21End of August 2026
Skippedv20.1End of June 2026
v1.3.0v20End of June 2026
Skippedv19.2End of February 2026
Skippedv19.1End of February 2026
Skippedv19End of February 2026
Skippedv18End of September 2025
Skippedv17.1End of May 2025
v1.2.0 DEPRECATEDv17End of May 2025
Skippedv16.1End of January 2025
Skippedv16End of January 2025
v1.1.0 DEPRECATEDv15End of September 2024
v1.0.1 DEPRECATEDv14End of May 2024

Requirements

Installation

$ go get github.com/Optable/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)
iferr!=nil {
panic(err)
}
deferconn.Close()
  1. Start making calls.
customerServiceClient:=services.NewCustomerServiceClient(conn)
accessibleCustomers, err:=customerServiceClient.ListAccessibleCustomers(
ctx,
&services.ListAccessibleCustomersRequest{},
)
iferr!=nil {
panic(err)
}
for_, customer:=rangeaccessibleCustomers.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)
iferr!=nil {
panic(err)
}
request, err:=http.NewRequest("GET", "https://googleads.googleapis.com/v14/customers:listAccessibleCustomers", bytes.NewBuffer(requestBody))
iferr!=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=headerclient:=&http.Client{}
response, err:=client.Do(request)
iferr!=nil {
panic(err)
}
deferresponse.Body.Close()
varresponseBody []byteifresponseBody, err=io.ReadAll(response.Body); err!=nil {
panic(err)
}
listAccessibleCustomersResponse:=new(services.ListAccessibleCustomersResponse)
iferr:=protojson.Unmarshal(response, listAccessibleCustomersResponse); err!=nil {
panic(err)
}
for_, customer:=rangelistAccessibleCustomersResponse.ResourceNames {
fmt.Println("ResourceName: "+customer)
}

Examples

See clients/internal/snippets.

Note for the updating process

  1. Find the version number in this folder.
  2. Run git checkout -b bump-to-v15 (change the version accordingly).
  3. Run make generate to generate the code.
  4. It will prompt you to enter the version number. Enter the version number you found in step 1, without the v. Example: For v15, enter 15.
  5. Once the process is done, it should have modified some files in /clients and /protogen
  6. Modify this readme.md to add the version number to the table with the next tag (ref: https://developers.google.com/google-ads/api/docs/sunset-dates)
  7. Create a PR with the changes against https://github.com/Optable/google-ads-pb/tree/main.
  8. Create a tag with the PR merged in step 7. git tag -a v1.1.0 -m "update to v15"
  9. Mark the pushed tag as Latest release in GitHub: https://github.com/Optable/google-ads-pb/releases/edit/v1.1.0
  10. Publish the release on Golang GOPROXY=proxy.golang.org go list -m github.com/Optable/google-ads-pb@v1.1.0

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.

About

Google Ads API Client Library for Golang

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages