Giter Site home page Giter Site logo

adworj's Introduction

adworj

Clojure library to ease interacting with the Google AdWords API. It is built upon Google's AdWords API Java Client Library.

OAuth 2 Authentication

Google's APIs are moving towards requiring OAuth 2 authentication. To do this you need to:

  1. Visit https://console.developers.google.com/ and (if necessary create a project).
  2. Click on Credentials in the API & auth menu on the left.
  3. Ceate a new Client ID for a native application. The redirect URI should be: urn:ietf:wg:oauth:2.0:oob
  4. You'll also need your AdWords API developer token.

Once you've generated all the tokens and keys you can use adworj.credentials namespace to help generate the necessary credentials.

Ultimately you need to retrieve the refresh token that is provided by the OAuth Credentials. Having retrieved this during the OAuth flow you can either create offline-credentials using the refresh token directly, or, store the refresh token in your ads.properties.

ads.properties

The easiest way to configure Google's client library is via a properties file. This should look something like:

api.adwords.clientId=(from the developer console above)
api.adwords.clientSecret=(from the developer console above)
api.adwords.developerToken=(from the adwords console)

Once you've authenticated you can add an entry for the refresh token:

api.adwords.refreshToken=(from oauth authentication/authorization flow)

Reporting API

Having successfully authenticated, and updated the properties file with your configuration, you can run a report as follows:

(ns reporter
  (:require [adworj.credentials :as ac]
             [adworj.reporting :as ar]
             [clojure.java.io :as io]))

(def client-customer-id "123-456-7890")
(def credentials        (ac/offline-credentials "./ads.properties"))
(def session            (ar/reporting-session "./ads.properties" credentials
                                              :client-customer-id client-customer-id
                                              :include-zero-impressions false))

(with-open [report (ar/run session ar/paid-and-organic-query "sample report" :range (ar/date-range :last-week))]
  (doseq [record (ar/record-seq report)]
    (println record)))))

License

Copyright © 2015 uSwitch Limited.

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

adworj's People

Contributors

christianblunden avatar pingles avatar shelleyallen avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.