Google Ads API Client Library for Golang

This is a Golang client library for accessing the Google Ads API. Most of the code is generated from the googleapis repository. We only make some modifications and examples. Detailed informations can be found on workflows/generator.
Please note that this is not an official project. But we think it is very low risk because it is a very mature project, and we have been using it in production for more than two years. The only thing to note is the sunset schedule of the Google Ads API.
Features
- Fully support for Google Ads API.
- Support for GRPC calls.
- Support for HTTP calls by using protojson.
- Frequent updates based on official repository.
Version support
google-ads-pb |
Google Ads API |
Sunset date |
v1.5.0 |
v14 |
End of May 2024 |
v1.4.1 |
v13.1 |
End of January 2024 |
v1.4.0 |
v13 |
End of January 2024 |
v1.3.1 |
v12 |
End of September 2023 |
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
- Set the environment variables.
$ export ACCESS_TOKEN=<your access token>
$ export DEVELOPER_TOKEN=<your developer token>
$ export CUSTOMER_ID=<your customer id>
- Create 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()
- Make the first call.
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)
}
- Make HTTP calls with using protojson is not recommended now. But it is available yet, for more information please refer to the code in examples.
Examples
Account management
Campaign management
Here are some related projects
Contributing
Welcome to contribute more examples and documentations.
Supporting
If you like this project, please consider buying me a coffee. 😄
