Skip to content

This package provides a simple way to interact with PlayStation's API. It includes methods to fetch user information and games.

License

Notifications You must be signed in to change notification settings

FrostBreker/go-playstation-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Reference

go-playstation-api

This package provides a simple way to interact with PlayStation's API. It includes methods to fetch user information and games.

Read First

Corresponding to my research how PSN works you need npsso to interact with Sony servers. Instructions how to get it below.

How to get NPSSO

  1. Open your browser and go to https://my.playstation.com/
  2. Login to your account
  3. Open https://ca.account.sony.com/api/v1/ssocookie in new tab

Functionality

  • You can get user profile info
  • You can get user games info

Installation

go get github.com/FrostBreker/go-playstation-api

Usage

package main

import (
	"context"
	"log"
	"net/http"
	"github.com/FrostBreker/go-playstation-api"
	"time"
)

func main() {
	// Handle errors from option functions
	regionOpt, err := playstation.WithRegion(playstation.RegionFR)
	if err != nil {
		log.Fatalf("Error setting region: %v", err)
	}

	langOpt, err := playstation.WithLanguage(playstation.LangFR)
	if err != nil {
		log.Fatalf("Error setting language: %v", err)
	}

	clientOpt, err := playstation.WithClient(&http.Client{})
	if err != nil {
		log.Fatalf("Error setting HTTP client: %v", err)
	}

	// Create the client using the package and use the options to set the region and lang to fr and use an HTTP client
	client := playstation.NewClient(regionOpt, langOpt, clientOpt)

	// Use the client variable to avoid unused variable error
	log.Printf("Client created: %+v", client)

	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()

	// Use the client to authenticate
	clientAPI, err := client.Authenticate(ctx, "your-npsso")
	if err != nil {
		log.Fatalf("Error authenticating: %v", err)
	}

	// Use the clientAPI to get user account, profile, and games

	// Use the clientAPI to get the user account id
	userAccount, err := clientAPI.GetUserAccountId(ctx, "james")
	if err != nil {
		log.Fatalf("Error getting user account id: %v", err)
	}

	log.Printf("User account id: %+v", userAccount)

	// Use the user account to get the user profile
	userProfile, err := clientAPI.GetUserProfile(ctx, userAccount.Profile.AccountID)
	if err != nil {
		log.Fatalf("Error getting user profile: %v", err)
	}

	log.Printf("User profile: %+v", userProfile)

	// Use the user account to get the user games
	userGames, err := clientAPI.GetUserGames(ctx, userAccount.Profile.AccountID)
	if err != nil {
		log.Fatalf("Error getting user games: %v", err)
	}

	log.Printf("User games: %+v", userGames)
}

This project highly inspired by https://github.com/Tustin/psn-php and https://github.com/sizovilya/go-psn-api.

About

This package provides a simple way to interact with PlayStation's API. It includes methods to fetch user information and games.

Topics

Resources

License

Stars

Watchers

Forks

Languages