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:
-
(*) sessionId=[any sessionId]
https://geekweb.com/api/psn/getid/out.php?sessionId=[YourSessionId]
-
source=[us|eumypsn|euforums]
The api can get the proper PSN-ID by different sources.
Choose the once you want to get the PSN-ID from.
('us' is the default value)
Example1: https://geekweb.com/api/psn/getid/out.php?sessionId=[YourSessionId]&source=us
Example2: https://geekweb.com/api/psn/getid/out.php?sessionId=[YourSessionId]&source=eumypsn
Example3: https://geekweb.com/api/psn/getid/out.php?sessionId=[YourSessionId]&source=euforums
-
error=[0,1]
This parameter handles the PHP error outputs.
('0' is the default value.)
Example1: https://geekweb.com/api/psn/getid/out.php?sessionId=[YourSessionId]&error=0
(output no php errors by error_reporting(0);)
Example2: https://geekweb.com/api/psn/getid/out.php?sessionId=[YourSessionId]&error=1
(output all php errors by error_reporting(E_ALL);)
(*) => 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:
-
(*) returnURL=[any url]
https://geekweb.com/api/psn/getid/out.php?returnURL=[YourReturnUrl]
This is the url of your site. This script forwards the user to that
returnURL with the proper sessionId by GET.
and with the following POST parameters:
-
(*) userName=[any email]
Your email address for the authentication.
-
(*) password=[any password]
Your password for the authentication.
(*) => 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, $newid, PREG_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