GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - FuzzyStatic/blizzard: Go client library for Blizzard API data

BranchesTags
Open more actions menu

Latest commit

 

History

276 Commits
276 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
d3c
d3c
 
 
d3gd
d3gd
 
 
examples
examples
 
 
hsgd
hsgd
 
 
oauth
oauth
 
 
owl
owl
 
 
sc2c
sc2c
 
 
sc2gd
sc2gd
 
 
sps
sps
 
 
wow
wow
 
 
wowcgd
wowcgd
 
 
wowgd
wowgd
 
 
wowp
wowp
 
 
wowsearch
wowsearch
 
 
.gitignore
.gitignore
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
blizzard.go
blizzard.go
 
 
d3c.go
d3c.go
 
 
d3c_test.go
d3c_test.go
 
 
d3gd.go
d3gd.go
 
 
d3gd_test.go
d3gd_test.go
 
 
errors.go
errors.go
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
header.go
header.go
 
 
hsgd.go
hsgd.go
 
 
hsgd_test.go
hsgd_test.go
 
 
init_test.go
init_test.go
 
 
oauth.go
oauth.go
 
 
oauth_test.go
oauth_test.go
 
 
owl.go
owl.go
 
 
owl_test.go
owl_test.go
 
 
region_string.go
region_string.go
 
 
sc2c.go
sc2c.go
 
 
sc2c_test.go
sc2c_test.go
 
 
sc2gd.go
sc2gd.go
 
 
sc2gd_test.go
sc2gd_test.go
 
 
sps.go
sps.go
 
 
sps_test.go
sps_test.go
 
 
wowc1xgd.go
wowc1xgd.go
 
 
wowcanngd.go
wowcanngd.go
 
 
wowcgd.go
wowcgd.go
 
 
wowcgd_test.go
wowcgd_test.go
 
 
wowgd.go
wowgd.go
 
 
wowgd_test.go
wowgd_test.go
 
 
wowp.go
wowp.go
 
 
wowp_test.go
wowp_test.go
 
 

Repository files navigation

blizzard

Go Reference Go Report Card

This is a Go client library for gathering Blizzard API reference data

Table of Contents

  • blizzard
    • Table of Contents
    • Getting Started
      • Fetching Diablo 3 Data
      • Fetching Hearthstone Data
      • Fetching Overwatch League Data
      • Fetching StarCraft 2 Data
      • Fetching World of Warcraft Data
      • Fetching World of Warcraft Classic Data
    • Authorization for User Data
      • Fetching OAuth Data
      • Streaming Provider Service (Playable Titles)
    • Header Information
    • Documentation
    • Special Thanks

Getting Started

First, download the Blizzard library:

go get github.com/FuzzyStatic/blizzard/v3

Start using the library by initiating a new Blizzard config structure for your desired region and locale (client_id and client_secret can be acquired through your developer account at https://develop.battle.net/) and requesting an access token:

usBlizzClient, err := blizzard.NewClient(blizzard.Config{
  ClientID:     "my_client_id",
  ClientSecret: "my_client_secret",
  HTTPClient:   http.DefaultClient,
  Region:       blizzard.US,
  Locale:       blizzard.EnUS,
})

err = usBlizzClient.AccessTokenRequest(ctx)
if err != nil {
  fmt.Println(err)
}

euBlizzClient, err := blizzard.NewClient(blizzard.Config{
  ClientID:     "my_client_id",
  ClientSecret: "my_client_secret",
  HTTPClient:   http.DefaultClient,
  Region:       blizzard.EU,
  Locale:       blizzard.EnGB,
})

err = euBlizzClient.AccessTokenRequest(ctx)
if err != nil {
  fmt.Println(err)
}

Fetching Diablo 3 Data

You can use the functions prefixed with "D3" to acquire Diablo 3 information. For example, you can get information about the current D3 hardcore necromancer leaderboards:

dat, _, err := usBlizzClient.D3SeasonLeaderboardHardcoreNecromancer(ctx, 15)
if err != nil {
  fmt.Println(err)
}

fmt.Printf("%+v\n", dat)

Fetching Hearthstone Data

You can use the functions prefixed with "HS" to acquire Hearthstone information. For example, you can get information about all the Hearthstone cards:

dat, _, err := usBlizzClient.HSCardsAll(ctx)
if err != nil {
  fmt.Println(err)
}

fmt.Printf("%+v\n", dat)

Fetching Overwatch League Data

You can use the functions prefixed with "OWL" to acquire Overwatch League information. For example, you can get information about the Overwatch League:

dat, _, err := usBlizzClient.OWLSummaryData(ctx)
if err != nil {
  fmt.Println(err)
}

fmt.Printf("%+v\n", dat)

Fetching StarCraft 2 Data

You can use the functions prefixed with "SC2" to acquire StarCraft 2 information. For example, you can get information about the current SC2 grandmaster ladder:

dat, _, err := usBlizzClient.SC2LadderGrandmaster(ctx, blizzard.EU)
if err != nil {
  fmt.Println(err)
}

fmt.Printf("%+v\n", dat)

Fetching World of Warcraft Data

You can use the functions prefixed with "WoW" to acquire World of Warcraft information. For example, you can get information about your WoW character profile:

dat, _, err := usBlizzClient.WoWCharacterProfileSummary(ctx, "illidan", "wildz")
if err != nil {
  fmt.Println(err)
}

fmt.Printf("%+v\n", dat)

or get information about specific spells:

dat, _, err := usBlizzClient.WoWSpell(ctx, 17086)
if err != nil {
  fmt.Println(err)
}

fmt.Printf("%+v\n", dat)

or the PvP leaderboards:

dat, _, err := usBlizzClient.WoWCharacterPvPBracketStatistics(ctx, wowp.Bracket3v3)
if err != nil {
  fmt.Println(err)
}

fmt.Printf("%+v\n", dat)

Fetching World of Warcraft Classic Data

You can use the functions prefixed with "ClassicWoW" to acquire World of Warcraft Classic information. Blizzard provides data for three Classic versions: Era (the original Classic experience), Anniversary (the enhanced Classic edition), and Progression (the current Classic progression).

For example, you can get information about WoW Classic Era creature data:

dat, _, err := usBlizzClient.ClassicWoWEraCreature(ctx, 30)
if err != nil {
  fmt.Println(err)
}

fmt.Printf("%+v\n", dat)

Or get information about WoW Classic Anniversary creature data:

dat, _, err := usBlizzClient.ClassicWoWAnniversaryCreature(ctx, 30)
if err != nil {
  fmt.Println(err)
}

fmt.Printf("%+v\n", dat)

Or get information about WoW Classic Progression creature data:

dat, _, err := usBlizzClient.ClassicWoWCreature(ctx, 30)
if err != nil {
  fmt.Println(err)
}

fmt.Printf("%+v\n", dat)

Authorization for User Data

To use the UserInfoHeader or WoWUserCharacters functions to acquire data about other users (and not your own), you must use the OAuth2 redirect method to get an authorized token. This is useful for building websites that display more personal or individualized data. The following code snippet is an example on how to acquire authorized tokens for other users. A working example can be found in the examples/authCodeFlow directory. Before the redirect URI will work, you will have to add it to your client settings at https://develop.battle.net/access:

package main

import (
  "context"
  "encoding/json"
  "fmt"
  "log"
  "net/http"

  "github.com/FuzzyStatic/blizzard/v3"
  "github.com/FuzzyStatic/blizzard/v3/oauth"
  "golang.org/x/oauth2"
)

var (
  cfg           oauth2.Config
  usBlizzClient *blizzard.Client
)

// Homepage
func HomePage(w http.ResponseWriter, r *http.Request) {
  fmt.Println("Homepage Hit!")
  u := cfg.AuthCodeURL("my_random_state")
  http.Redirect(w, r, u, http.StatusFound)
}

// Authorize
func Authorize(w http.ResponseWriter, r *http.Request) {
  err := r.ParseForm()
  if err != nil {
    http.Error(w, err.Error(), http.StatusInternalServerError)
    return
  }

  state := r.Form.Get("state")
  if state != "my_random_state" {
    http.Error(w, "State invalid", http.StatusBadRequest)
    return
  }

  code := r.Form.Get("code")
  if code == "" {
    http.Error(w, "Code not found", http.StatusBadRequest)
    return
  }

  token, err := cfg.Exchange(context.Background(), code)
  if err != nil {
    http.Error(w, err.Error(), http.StatusInternalServerError)
    return
  }

  e := json.NewEncoder(w)
  e.SetIndent("", "  ")
  err = e.Encode(*token)
  if err != nil {
    http.Error(w, err.Error(), http.StatusInternalServerError)
    return
  }

  dat1, _, err := usBlizzClient.UserInfoHeader(token)
  if err != nil {
    http.Error(w, err.Error(), http.StatusInternalServerError)
    return
  }

  fmt.Printf("%+v\n", dat1)

  dat2, _, err := usBlizzClient.WoWUserCharacters(token)
  if err != nil {
    http.Error(w, err.Error(), http.StatusInternalServerError)
    return
  }

  fmt.Printf("%+v\n", dat2)
}

func main() {
  blizz = blizzard.NewClient("client_id", "client_secret", blizzard.US, blizzard.EnUS)
  cfg = usBlizzClient.AuthorizeConfig("http://<mydomain>:9094/oauth2", oauth.ProfileD3, oauth.ProfileSC2, oauth.ProfileWoW)

  http.HandleFunc("/", HomePage)
  http.HandleFunc("/oauth2", Authorize)

  // We start up our Client on port 9094
  log.Println("Client is running at 9094 port.")
  log.Fatal(http.ListenAndServe(":9094", nil))
}

Fetching OAuth Data

Now you can validate those tokens with the OAuth API:

dat, _, err := usBlizzClient.TokenValidation(ctx, token)
if err != nil {
  fmt.Println(err)
}

fmt.Printf("%+v\n", dat)

Streaming Provider Service (Playable Titles)

Cloud‑gaming partners can ask Blizzard which titles a given user is allowed to launch. To do this, request the streaming.titles and openid scopes when building the authorization URL. After the user completes the OAuth flow you will have an access token suitable for SPS.

Use the new SPSPlayableTitles helper to call the service:

pts, hdr, err := usBlizzClient.SPSPlayableTitles(ctx, token)
if err != nil {
    fmt.Println(err)
}

for _, t := range pts.Titles {
    fmt.Printf("%d: %s\n", t.ID, t.Name)
}

The response contains every eligible title or sub‑title available to the account.

For a complete runnable example, see examples/sps.

Header Information

Each API call will return HTTP response header information, if any. Use the second return variable to get a structure containing the response header information.

dat, header, err := usBlizzClient.WoWAuctions(context.Background(), 1138)
if err != nil {
  fmt.Println(err)
}

fmt.Println(header.BattlenetNamespace)
fmt.Println(header.LastModified)
...

Documentation

See the Blizzard API reference and the Go reference for all the different datasets that can be acquired. For questions and discussion about the blizzard API go to the Blizzard API Forum.

Special Thanks

Thanks to JSON-to-Go for making JSON to Go structure creation simple.

Thanks to all who contribute to keep this package current.

About

Go client library for Blizzard API data

Topics

battlenetblizzardblizzard-apiblizzard-datad3diablo3gogolanghearthstonehearthstone-apioverwatchstarcraft-iistarcraft2starcraft2-apiworld-of-warcraftworld-of-warcraft-classicworldofwarcraftwowwow-api

Resources

Readme
MIT license

Contributing

Contributing
Activity

Stars

64 stars

Watchers

1 watching

Forks

21 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.