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

Created by: PSNAPI.ORG: http://psnapi.org/ | Sourced by | Licence: GNU GPL v3 | Last update: 2012-02-23 | Source Codes

Introduction

Sony has an official 'External PSN Sign In' page. You can set your own site as the returnURL by GET just if your url is allowed by Sony. We built our own SignIn Form that allowes every returnURL. 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 proper psnId by a sessionId

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

Get the sessionId by userName and password

Build your own form if you do not like our SignIn form.
https://geekweb.com/api/psn/getid/out.php with the following GET parameters: and with the following POST 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

$formUrl "https://geekweb.com/api/psn/getid/form.php?returnURL=";
$selfUrl "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 "https://geekweb.com/api/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);
    return isset(
$newid[0][1]) && $psnid == $newid[0][1];
}

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 sign in page
    // with your page url as returnURL by GET
    
header ("Location: " $formUrl urlencode($selfUrl));
}

?>



Created by: PSNAPI.ORG: http://psnapi.org/ | Sourced by | Licence: GNU GPL v3 | Last update: 2012-02-23 | Source Codes