API: GET PSN-ID by sessionId [stable] (v0.103)

Created by: PSNAPI.ORG: http://psnapi.org/ | Sourced by | Licence: GNU GPL v3 | Last update: 2010-06-27 | Source Codes

Introduction

Sony has an official 'External PSN Sign In' page. You can set your own site as the returnURL by GET. The site forwards to your site on a successfull sign in with a sessionId by GET. But there is no official public API to convert the sessionId into a user specific value (like the PSN-ID). This API here converts a valid sessionId into the proper PSN-ID. So everyone is able to use the Playstation Network SignIn for their own sites. Click here and sign in for a simple test.

Get the output

http://api.geekweb.org/psn/getid/out.php with the following GET parameters: (*) => Mandatory parameters

A small example for using this API

If you want to use this function on your own site, create a php file on your server and type in the following code:
<?

// Example for using the PSNAPI.ORG GetId API

$PSLogURL "https://store.playstation.com/external/index.vm?returnURL=";
$ThisURL "http://".$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"];

function 
getpsnid($sessId) {
    
$sources = array("us","eumypsn","euforums"); $psnid "0";
    for (
$i=0;isset($sources[$i]) && !isPsnIdValid($psnid);$i++) {
        
$url "http://api.geekweb.org/psn/getid/out.php?sessionId=" $sessId "&source=" $sources[$i];
        
$psnid file_get_contents($url);
    }
    return 
$psnid;
}

function 
isPsnIdValid($psnid) {
    
$regex '/([a-z].{2,15})/i';
    
preg_match_all($regex$psnid$newidPREG_SET_ORDER);
    if (isset(
$newid[0][1]) && $psnid == $newid[0][1]) { return true; } 
    return 
false;
}

if (isset(
$_GET['sessionId'])) {
    
// get the proper psnid by the given sessionId
    
$psnid getpsnid($_GET['sessionId']);
    
// TODO: connect with your user management here
    
echo ("Hi, <b>" $psnid "</b> ...");
} else {
    
// forward to the official external psn sign in page
    // with your page url as returnURL by GET
    
header ("Location: " $PSLogURL $ThisURL);
}

?>



Created by: PSNAPI.ORG: http://psnapi.org/ | Sourced by | Licence: GNU GPL v3 | Last update: 2010-06-27 | Source Codes