Coder Social home page Coder Social logo

google-adsense-example's Introduction

Google Adsense Example with Golang

This project shows that how Google Adsense API works with Golang.

Installation

$ go get -u github.com/odg0318/google-adsense-example

Get Started

  1. Make sure Google Adsense API is activated on Google API Console.
  2. Create OAuth2 Client ID on Google API Console and set redirect_uri to http://127.0.0.1:8080/auth
  3. cd $GOPATH/github.com/odg0318/google-adsense-example
  4. Set following environments; GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, GOOGLE_REDIRECT_URI
  5. Execute go build && ./google-adsense-example and a web server will run.
  6. Connect to http://127.0.0.1:8080/ on web browser and select your account to access.
  7. Some result of API will be shown on web browser.

Environment Variables

Environment Description
GOOGLE_CLIENT_ID Google OAuth2 Client ID
GOOGLE_CLIENT_SECRET Google OAuth2 Client Secret
GOOGLE_REDIRECT_URI Redirect URI that is used to receive an authorization code from Google.

Other Examples

You can check available API list here.

Accounts:list

client := oauth2Conf.Client(oauth2.NoContext, tok)
service, err := adsense.New(client)

call := service.Accounts.List()
resp, err := call.Do()

Accounts.reports:generate

client := oauth2Conf.Client(oauth2.NoContext, tok)
service, err := adsense.New(client)

call := service.Accounts.Reports()
call := report.Generate(accountId, fromDate, toDate)
call.Dimension("COUNTRY_CODE","DATE")
call.Metric("EARNINGS")
resp, err := call.Do()

With Refresh Token

Refresh Token is described in documentation.

url := oauth2Conf.AuthCodeURL("state", oauth2.AccessTypeOffline, oauth2.ApprovalForce)

References

google-adsense-example's People

Contributors

odg0318 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.