### Install Google Ads API Golang Client Source: https://github.com/shenzhencenter/google-ads-pb/blob/main/README.md Installs the Google Ads API client library for Golang using the go get command. Ensure you have Go 1.23 or later installed. ```bash go get github.com/shenzhencenter/google-ads-pb ``` -------------------------------- ### Google Ads API gRPC Search Example (Go) Source: https://github.com/shenzhencenter/google-ads-pb/blob/main/README.md Demonstrates how to perform a search query against the Google Ads API using gRPC in Go. It covers setting up the gRPC client, authentication with access tokens, and processing the search results. ```go var ( customerID = os.Getenv("CUSTOMER_ID") developerToken = os.Getenv("DEVELOPER_TOKEN") accessToken = os.Getenv("ACCESS_TOKEN") ) cred := grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, "")) conn, err := grpc.NewClient("googleads.googleapis.com:443", cred) if err != nil { panic(err) } defer conn.Close() ctx := context.Background() headers := metadata.Pairs( "authorization", "Bearer "+accessToken, "developer-token", developerToken, "login-customer-id", customerID, ) ctx = metadata.NewOutgoingContext(ctx, headers) req := &services.SearchGoogleAdsRequest{ CustomerId: customerID, Query: "SELECT user_list.name, user_list.resource_name FROM user_list", } svc := services.NewGoogleAdsServiceClient(conn) var header metadata.MD result, err := svc.Search(ctx, req, grpc.Header(&header)) requestId := header.Get("request-id") log.Printf("request-id: %v, login-customer-id: %v", requestId[0], customerID) if err != nil { apiErr := status.Convert(err) log.Fatalf("code: %s, message: %s, details: %v", apiErr.Code(), apiErr.Message(), apiErr.Details()) } for _, row := range result.Results { if row.UserList == nil { continue } log.Print("resource_name: ", row.UserList.GetResourceName(), " name: ", row.UserList.GetName()) } ``` -------------------------------- ### Google Ads API HTTP Search Example (Go) Source: https://github.com/shenzhencenter/google-ads-pb/blob/main/README.md Demonstrates how to perform a search query against the Google Ads API using HTTP POST requests in Go. It covers constructing the request, setting headers for authentication, and parsing the JSON response. ```go var ( customerID = os.Getenv("CUSTOMER_ID") developerToken = os.Getenv("DEVELOPER_TOKEN") accessToken = os.Getenv("ACCESS_TOKEN") ) var endpoint = fmt.Sprintf("https://googleads.googleapis.com/v18/customers/%s/googleAds:search", customerID) req := services.SearchGoogleAdsRequest{ Query: "SELECT user_list.name, user_list.resource_name FROM user_list", } reqBody, _ := protojson.Marshal(&req) reqHttp, _ := http.NewRequest("POST", endpoint, bytes.NewReader(reqBody)) header := make(http.Header) header.Set("content-type", "application/json") header.Set("authorization", "Bearer "+accessToken) header.Set("developer-token", developerToken) header.Set("login-customer-id", customerID) reqHttp.Header = header httpResp, err := http.DefaultClient.Do(reqHttp) if os.Getenv("DEBUG") != "" { reqId := httpResp.Header.Get("request-id") log.Print("request-id: ", reqId, " login-customer-id: ", reqHttp.Header.Get("login-customer-id")) } if err != nil { log.Panic(err) } defer httpResp.Body.Close() var httpRespBody []byte if httpRespBody, err = io.ReadAll(httpResp.Body); err != nil { log.Panic(err) } result := new(services.SearchGoogleAdsResponse) if err := protojson.Unmarshal(httpRespBody, result); err != nil { log.Fatal("failed to unmarshal response: ", err, "response: ", string(httpRespBody)) } for _, row := range result.Results { if row.UserList == nil { continue } log.Print("resource_name: ", row.UserList.GetResourceName(), " name: ", row.UserList.GetName()) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.