Skip to content

andytsunami/psn-lib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

#Unofficial PlayStation Network Library for Java Copyright 2012 Kroboth Software

License Apache 2.0

Sony hasn't published a public API interface for retrieving psn info so developers have to make their own implementation. Some examples are

While they are mostly server APIs, psn-lib is a pure Java Library.

Thanks to http://www.psnapi.com.ar/ for all the information they found.

##Client PlayStationNetworkClient is the client used to retrieve all network related data including profiles, games, and trophies.

PlayStationNetworkClient psnClient = new PlayStationNetworkClient();
// need to call init in order to set up client; authorizations, and cookies
psnClient.init();

The client is broken up into three types of data

  • Client - All data is retrieved from UK site and some is stored on the client. Includes friends, games, and trophies for current client login.
  • Public - Public games and trophies from US site.
  • Official - The term Official refers to data Sony devices retrieve which is more compact. The init method needs to be called before hand to set up authorizations.

Client Login

try {
  // progressListener is last argument, this case there is none. 
  psnClient.clientLogin("username", "password",null);
} catch (PlayStationNetworkException e) {
  // login was unsuccessful, which can mean if service is down
} catch (PlayStationNetworkLoginException e) {
	// username and password are incorrect
} catch (IOException e) {
	// IO Exception
}

This will retrieve UK and US login cookies, userinfo, Jid, and return PsnId.

Client Friends

try {
  psnClient.getClientFriendList();
} catch (PlayStationNetworkException e) {
	// problem parsing data
} catch (PlayStationNetworkLoginException e) {
	// login cookies invalid; needs login
} catch (IOException e) {
	// IO Exception
}

Public Games

try {
psnClient.getPublicGameList("psnId");
} catch (PlayStationNetworkException e) {
	// problem parsing data
} catch (IOException e) {
	// IO Exception
}

getPublicTrophyList() does however need US Login to get TICKET and PSNS2STICKET cookies. clientLogin will get these cookies automatically. Both cookies are static meaning they don't change value so it's possible to generate them and insert into CookieManager. Methods PsnUtils.createLoginCookieTicket() and PsnUtils.createLoginCookiePsnTicket() will create them based on any valid psnId. Note that psnId used for cookies doesn't have to same as one being used in getPublicTrophyList

Release v3.0.2

Calling init() in the client will generate TICKET and PSNS2STICKET cookies based on the value '*' [asterisk]. It seems as long as the cookies exist, any value is valid.

Official Games

try {
  // jid, start, max, Platforms
  psnClient.getOfficialGameList("jid", 0, 10, PlatformType.PS3, PlatformType.VITA);
} catch (IOException e) {
	// IO Exception
} catch (PlayStationNetworkException e) {
	// problem parsing data
}

##Values Jid is abbreviated for Jabble Id. Every registered psn Id has a Jid.

try {
  psnClient.getOfficialJid("psnId");
} catch (IOException e) {
	// IO Exception
}

Title Link Id refers to link Id for game on UK and US websites. http://us.playstation.com/playstation/psn/profile/trophies/582938-Warhawk Id is 582938-Warhawk. http://uk.playstation.com/psn/mypsn/trophies/detail/?title=4 Id is 4. It can also be retrieved by PsnGameData.getTitleLinkId()

Trophy Index is the index in which the trophy resides in a game.

##Network The client uses com.krobothsoftware.commons.network package as a helper for doing network connections, handling cookies, and authorizations.

NetworkHelper class can be retrieved by PlayStationNetworkClient.getNetworkHelper()

CookieManager cookieManager = networkHelper.getCookieManager();
cookieManager.putCookie(PsnUtils.createLoginCookieTicket("psnId"));
cookieManager.putCookie(PsnUtils.createLoginCookiePsnTicket("psnId"));

All cookies are made using builder class commons.network.values.Cookie.Builder

networkHelper
  	.setDefaultHeader("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201");
networkHelper.setDefaultConnectTimeout(5000); // millisecond
networkHelper.setDefaultReadTimeout(5000); // millisecond

Set-Default methods set value only if request connection hasn't set it; set if not set

ConnectionListener connListener = new ConnectionListener() {

	@Override
	public void onRequest(RequestBuilder builder) {
		// called right before connection is set up
	}

	@Override
	public void onFinish(URL url, HttpURLConnection connection) {
		// called after connection successfully or failed to connect

	}

};

networkHelper.addConnectionListener(connListener);

Listening on connections for networkHelper

Default Headers used

User-Agent AGENT_DEFAULT
Accept text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Accept-Encoding gzip, deflate
Accept-Charset UTF-8
`AGENT_DEFAULT` is different depending on OS, and platform ```` NetworkHelper/3.0.2 (Windows 7 6.1; Java 1.7.0_09) NetworkHelper/3.0.2 (Linux 3.0.31-00001-gf84bc96; samsung SCH-I500; Android 4.1.1) ````

##How to set up Go to Downloads and get lastest release. It includes library, source, Javadoc, and dependencies, This project depends on the following libraries

  • TagSoup - For parsing Html Data(websites)
  • SLF4J - Logging library

Releases v3.0.1 and below require [Html-Cleaner] (http://htmlcleaner.sourceforge.net/) instead of TagSoup.

There are two krobothcommons-vXXX.jar, one is for Android and other is SE. Make sure only to use one!

When working with Android, make sure to add internet permission in your manifest file.

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

Changelog

About

PlayStation Network Library for Java

Resources

Stars

Watchers

Forks

Packages

No packages published