Skip to content

Commit

Permalink
docs: update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
dqn committed Sep 14, 2020
1 parent d6a267b commit 1b17d3a
Showing 1 changed file with 30 additions and 48 deletions.
78 changes: 30 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# gonso

Go Nintendo Switch Online API
Nintendo Switch Online API wrapper written in Go.

## Installation

Expand All @@ -14,72 +14,54 @@ $ go get github.com/dqn/gonso
package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"

"github.com/dqn/gonso"
"github.com/dqn/gonso"
)

func main() {
sessionToken, err := gonso.Login()
if err != nil {
// handle error
}

// if you save the session token, you can skip the login next time

accessToken, err := gonso.Auth(sessionToken)
if err != nil {
// handle error
}

// example for Animal Crossing: New Horizons
url := "https://web.sd.lp1.acbaa.srv.nintendo.net/api/sd/v1/users"

req, _ := http.NewRequest("GET", url, nil)
req.Header.Set("Cookie", fmt.Sprintf("_gtoken=%s", accessToken))

resp, _ := http.DefaultClient.Do(req)
b, _ := ioutil.ReadAll(resp.Body)

var a struct {
Users []struct {
ID string `json:"id"`
Name string `json:"name"`
Image string `json:"image"`
Land struct {
ID string `json:"id"`
Name string `json:"name"`
DisplayID int `json:"displayId"`
} `json:"land"`
} `json:"users"`
}
json.Unmarshal(b, &a)

user := a.Users[0]
fmt.Println(user.Name, user.Land.Name) // => どきゅん プリズム
sessionToken, err := gonso.Login()
if err != nil {
// Handle error.
}

// if you save the session token, you can skip the login next time
// err := ioutil.WriteFile("session_token.txt", []byte(sessiontToken), 0644)
// if err != nil {
// // Handle error.
// }

accessToken, err := gonso.Auth(sessionToken)
if err != nil {
// Handle error.
}
}
```

```bash
authenticate by visiting this url: https://accounts.nintendo.com/connect/1.0.0/authorize?xxx=xxx
session token code: <input your session token code>
authenticate by visiting this url: https://accounts.nintendo.com/connect/1.0.0/authorize?...
session token code: <enter-your-session-token-code>
```

### How to get session token code

1. Select user and copy the link.
1. Visit the generated URL, select user and copy the link.

![](docs/copy_link.png)

2. You can get session token code from query params.
2. You can get session token code from the URL.

```
npf71b963c1b7b6d119://auth#session_state=xxx&session_token_code=xxx...
npf71b963c1b7b6d119://auth#...&session_token_code=<session-token-code>...
```
## See Also
This project is inspired by [splatnet2statink](https://github.com/frozenpandaman/splatnet2statink).
## License
MIT

0 comments on commit 1b17d3a

Please sign in to comment.