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.
- Fully support for Google Ads API.
- Support for GRPC calls.
- Support for HTTP calls by using protojson.
- Frequent updates based on official repository.
google-ads-pb | Google Ads API | Sunset date |
---|---|---|
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 |
Deprecated | ||
Deprecated | ||
Deprecated |
- Golang 1.4 or later.
- Before starting, recommend to read the OAuth2 guide.
- Apply for a developer token if you don't already have one.
$ go get -d github.com/shenzhencenter/google-ads-pb
- 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.
Here are some related projects
Welcome to contribute more examples and documentations.
If you like this project, please consider buying me a coffee. 😄