Skip to content

Simple golang package for fetching AWQL query results

License

Notifications You must be signed in to change notification settings

habibrosyad/go-awql

Repository files navigation

go-awql

Build Status GoDoc

A simple package to fetch AWQL query results. Currently only support querying against Adwords report, support for services will come later.

Usage

Import the package.

import github.com/habibrosyad/go-awql

Fill the authentication details.

auth := &awql.Auth{
	ClientId:       "your-client-id.apps.googleusercontent.com",
	ClientSecret:   "your-client-secret",
	RefreshToken:   "your-refresh-token",
	AccessToken:    "your-access-token",
	CustomerId:     "your-customer-id",
	DeveloperToken: "your-developer-token",
}

Create a new client.

client := awql.NewClient(auth)

Begin querying. This sample is for querying Adwords report.

rows, err := client.Query("SELECT Date, ActiveViewCtr FROM ACCOUNT_PERFORMANCE_REPORT DURING TODAY");
if err != nil {
	panic(err) // Can not continue, do error handling.
}

defer rows.Close()

for rows.Next() {
	row, err := rows.Scan()
	if err != nil {
		// Do error handling.
	}
	// Do anthing with the returned row.
	// Result is automatically mapped to its respective field in the AWQL definition.
	// E.g. to access the previous result you can use row["Date"] and row["ActiveViewCtr"].
}

The returned result from rows.Scan() is map[string]interface{}. To map the result into a struct you might want to use mapstructure. Key of the map is the same as the field used in the AWQL definition. For example, in the previous sample you can access the result as row["Date"] and row["ActiveViewCtr"].

About

Simple golang package for fetching AWQL query results

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages