Skip to content

revealbot/google-ads-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

fd6bfd0 · Jan 17, 2024

History

65 Commits
Jan 17, 2022
Mar 9, 2022
Feb 6, 2019
Jan 17, 2024
Jan 17, 2024
Jan 17, 2024
Jan 17, 2024
Jan 17, 2024
Jan 17, 2024
Jun 19, 2023
Sep 25, 2018
Sep 24, 2018
Mar 9, 2022
Jan 17, 2022
Jan 17, 2024
Jan 17, 2022
Jan 17, 2024
Jan 17, 2024
Dec 19, 2022
Mar 9, 2022
Jan 17, 2022

Repository files navigation

google-ads-go

Google Ads API version v0_7_0
Build CircleCI
Release Release

Features

Installation

To install, simply run:

$ go get -d github.com/revealbot/google-ads-go

Make sure your PATH includes the $GOPATH/bin directory if you want to use the CLI utils:

export PATH=$PATH:$GOPATH/bin

Example

package main

import (
  "fmt"

  "github.com/revealbot/google-ads-go/ads"
  "github.com/revealbot/google-ads-go/services"
)

func main() {
  // Create a client from credentials file
  client, err := ads.NewClientFromStorage("google-ads.json")
  if err != nil {
    panic(err)
  }
  
  // Load the "GoogleAds" service
  googleAdsService := services.NewGoogleAdsServiceClient(client.Conn())
  
  // Create a search request
  request := services.SearchGoogleAdsRequest{
    CustomerId: "2984242032",
    Query:      "SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id",
  }
  
  // Get the results
  response, err := googleAdsService.Search(client.Context(), &request)
  for _, row := range response.Results {
    campaign := row.Campaign
    fmt.Printf("id: %d, name: %s\n", campaign.Id.Value, campaign.Name.Value)
  }
}

When using the NewGoogleAdsClientFromStorage method, you must provide a path to a valid google-ads.json file (containing your Google Ads API credentials).

{
    "client_id": "YOUR_CLIENT_ID",
    "client_secret": "YOUR_CLIENT_SECRET",
    "refresh_token": "YOUR_REFRESH_TOKEN",
    "developer_token": "YOUR_DEVELOPER_TOKEN"
}

CLI

This library also provides some CLI utilities for generating/refreshing Google OAuth2 credentials. The newly generated token will be printed to stdout, as well as the expiry timestamp.

Generate Access Token from Refresh token

$ gads refresh -client-id CLIENT_ID -client-secret CLIENT_SECRET -refresh-token REFRESH_TOKEN

Generate Access Token from JSON credentials file

$ gads refresh -file credentials.json

Additionally, you can use the -help flag for more information: gads refresh --help

Contributing

Compiling

All build scripts use Makefile

Build and run

$ make run

Run with gRPC debugging output

$ make run-debug

Changelog

To see the changes between Google Ads API versions, take a look at the official Google Ads API Release Notes.

Manually Building Protos

Building .pb.go files from the original googleads protos should only be done when updating to a new Google Ads version.

Requirements:

Build .pb.go protos:

$ make protos

About

Google Ads API client library for Golang

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 51.9%
  • Starlark 35.5%
  • Shell 7.2%
  • Makefile 5.4%