psn-php icon indicating copy to clipboard operation
psn-php copied to clipboard

Trophy Earned Rate Not Working Anymore?

Open Argosth opened this issue 8 months ago • 12 comments

I was using earnedRate() function yesterday and was working fine, but now, I get 0 for every trophy linked to a player, do you know if this a temporary issue or now is blocked by the PSN Api?

Thank you :)

Argosth avatar Oct 24 '23 08:10 Argosth

I noticed that on my PS5 console around the time you wrote this issue so was it really slow on loading trophies. Might have been a Sony hiccup.

Ragowit avatar Oct 24 '23 10:10 Ragowit

I noticed that on my PS5 console around the time you wrote this issue so was it really slow on loading trophies. Might have been a Sony hiccup.

Still not working but the API is too slow at this moment, so maybe they will fix this soon, or what do you think?

Argosth avatar Oct 24 '23 17:10 Argosth

Honestly, I don't know. And you're sure you haven't made any changes to your code?

I have a strange bug that this tool only grabs the first data I ask for about a trophy linked to the player. See #250 for it (and my workaround).

Ragowit avatar Oct 24 '23 19:10 Ragowit

Honestly, I don't know. And you're sure you haven't made any changes to your code?

I have a strange bug that this tool only grabs the first data I ask for about a trophy linked to the player. See #250 for it (and my workaround).

This is my code:

$user = $client->users()->find($userAccount); foreach ($user->trophyTitles() as $game) foreach ($game->trophyGroups() as $trophyGroup) { foreach ($trophyGroup->trophies() as $trophy) { $trophyDate = (clone $trophy)->earnedDateTime(); $trophyRate = $trophy->earnedRate();`

I used your solution but still not working :(

I tried your solution: $trophyDate = (clone $trophy)->earnedDateTime(); but nothing, and I realized that earnedDateTime is not working too, so both returns 0. Any ideas?

Argosth avatar Oct 25 '23 06:10 Argosth

Strange, seems fine to me. What PHP version are you running? For reference, I'm using PHP 8.2

Ragowit avatar Oct 25 '23 06:10 Ragowit

Strange, seems fine to me. What PHP version are you running? For reference, I'm using PHP 8.2

My version is 8.2.4, and the thing is that two days ago was working fine. Did you try to update a user PSN Trophies? When I do that, always retrieve 0 from earnedDateTime and earnedRate, should I put clone in both variables?

Ty Ragowit.

Argosth avatar Oct 25 '23 09:10 Argosth

My site https://psn100.net updates just fine.

No, clone on both shouldn't be needed. Have you tried to update your npsso on the account your using with the script?

Ragowit avatar Oct 25 '23 09:10 Ragowit

My site https://psn100.net updates just fine.

No, clone on both shouldn't be needed. Have you tried to update your npsso on the account your using with the script?

This is the method I'm using right now:

/* Link Login PSN: https://www.playstation.com/ */
/* Get NPSSO: https://ca.account.sony.com/api/v1/ssocookie */

$npsso = $DatabaseOperations->getNpsso(); /* From My Database */
define('NPSSO', $npsso['npsso']);
    
/* PSN Tustin Declarations */
use Tustin\PlayStation\Client;
$client = new Client();
$client->loginWithNpsso(NPSSO);
$refreshToken = $client->getRefreshToken()->getToken(); // Save this code somewhere (database, file, cache) and use this for future logins
/* PSN Tustin Declarations */

When I try to use the verbose method, it returns this errors from navigator console:

Error with Permissions-Policy header: Unrecognized feature: 'document-domain'. POST https://auth.api.sonyentertainmentnetwork.com/2.0/ssocookie 403 (Forbidden)

Then I log-out my current psn session and seems to be working with the verbose method, but with some erros.

And if I try to use the $client->login('npsso'); Api returns that the method login doesn't exists, do you see something wrong?

Argosth avatar Oct 25 '23 10:10 Argosth

Seems good, here's my login code for reference:

try {
    $client = new Client();
    $npsso = GetNpssoFromDatabase();
    $client->loginWithNpsso($npsso);
} catch (Exception $e) {
    echo "Something went wrong with login.";
}

Ragowit avatar Oct 25 '23 11:10 Ragowit

Seems good, here's my login code for reference:

try {
    $client = new Client();
    $npsso = GetNpssoFromDatabase();
    $client->loginWithNpsso($npsso);
} catch (Exception $e) {
    echo "Something went wrong with login.";
}

Hello Ragowit, now, with the next code, I'm getting trophy rate correctly, but no the earnedDateTime()

`require_once 'includes/psn.php';

$user = $client->users()->find('9150243351170436908');
foreach ($user->trophyTitles() as $game) {
    $platforms = $game->platform();
    foreach ($game->trophyGroups() as $trophyGroup) {
        foreach ($trophyGroup->trophies() as $trophy) {
            $trophyRate = $trophy->earnedRate(); 
            $trophyDate = (clone $trophy)->earnedDateTime();
            $trophyType = $trophy->type();
            
            echo("<br />Rate: ".$trophyRate."<br />");
            echo("<br />Date: ".$trophyDate."<br />");
            echo("<br />Trphy Type: ".$trophyType."<br />");
            echo("<br />Platform: " . implode(", ", $platforms) . "<br />");
        }
    }
}`

Trophy Platform, type and rate are ok, but date is returning null, any ideas?

Argosth avatar Oct 26 '23 13:10 Argosth

The date can be null, mostly common in the PS3 era. Are you sure that the date in this case isn't suppose to be null? Have you compared that user with other sites? (I don't know who 9150243351170436908 is)

Ragowit avatar Oct 27 '23 20:10 Ragowit

The date can be null, mostly common in the PS3 era. Are you sure that the date in this case isn't suppose to be null? Have you compared that user with other sites? (I don't know who 9150243351170436908 is)

Ok, found the problem and the solution:

  • The account I was using is an old account and maybe it doesn't have trophy date, so I test with another account and realized that, if you separate earnedRate with earnedDateTime in different blocks, will works, but, also earnedDateTime must be the first in the line just after the new block, for example:
foreach ($trophyGroup->trophies() as $trophy) {
   $trophyRate = $trophy->earnedRate(); /* Separated. */
      if ($trophy->earned()) {
         $trophyDate = $trophy->earnedDateTime(); /* In the first Line after If. */
         $trophyProgress = $trophy->progress();
         $trophyName = $trophy->name();
        $trophyType = $trophy->type();
      }
}

If you put earnedDateTime() just after the if, it works fine, but if you set that line after progress, name or another one, it will return null, seems weird, I also try to use clone but nothing, so that's it, earnedRate before (earned()) and earnedDateTime just after the conditional.

Thank you Ragowit, thanks to you I found the strange solution hehehe.

Argosth avatar Oct 28 '23 06:10 Argosth