Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How Can I Show Every AccountId Searched? #248

Open
Argosth opened this issue Apr 24, 2023 · 15 comments
Open

How Can I Show Every AccountId Searched? #248

Argosth opened this issue Apr 24, 2023 · 15 comments

Comments

@Argosth
Copy link

Argosth commented Apr 24, 2023

Hello, I'm trying to use this API again, and thanks in advance for this work.

I want to use AccountID of every user instead of "onlineId", and the problem is that when I try to access the object values, I can't go directly to every user Account ID that matched the criteria, how can I show or save every data?

For example:
$users = $client->users()->search('tustin25');
foreach($users as $user) { // How can I get every user AccountID? }

Thanks for your help.

@Ragowit
Copy link
Collaborator

Ragowit commented Apr 24, 2023

$users = $client->users()->search('tustin25');
foreach($users as $user) {
  echo $user->accountId() ."<br>";
}

@Argosth
Copy link
Author

Argosth commented Apr 24, 2023

$users = $client->users()->search('tustin25');
foreach($users as $user) {
  echo $user->accountId() ."<br>";
}

Thank you for your quick response, is there a chance to get also the Country and Language from Search() option? Or should I go for that information with "find('accountId')" method?

Thank you.

@Ragowit
Copy link
Collaborator

Ragowit commented Apr 24, 2023

Country, yes. Look at https://github.com/Tustin/psn-php/blob/master/src/Model/User.php to see all of the methods available.

psn-php/src/Model/User.php

Lines 128 to 136 in 5d9a357

/**
* Gets the user's country.
*
* This property will only be available if the user was obtained via the user search endpoint.
*/
public function country(): ?string
{
return $this->country;
}

Please note that country is only obtained via search(), and not via find(). This is a limitation from Sony, not this API.

Don't know what you mean about language.

EDIT: Found this, but I have never used it.

psn-php/src/Model/User.php

Lines 205 to 211 in 5d9a357

/**
* Gets all the user's languages.
*/
public function languages(): array
{
return $this->pluck('languagesUsed');
}

Also: https://tustin.dev/psn-php/#/users?id=languages

@Argosth
Copy link
Author

Argosth commented Apr 26, 2023

Thank you very much Ragowit, you are always here helping noobs like me hehehe

One question, when I try to get title->platform(), I get this enum error: Fatal error: Uncaught Error: Cannot instantiate enum Tustin\PlayStation\Enum\ConsoleType), I see that consoleType is a enum type and platform() function return an array, but I don't know why I receive that error, I have PHP 8.2.

And final question, I manage to get all games with the trophy summary of an specific player, the question is: How can I get now the trophies associated that the player has earned?

Thank you again Ragowit.

@Ragowit
Copy link
Collaborator

Ragowit commented Apr 26, 2023

For platforms, I believe I did this hack (there's certainly a cleaner way):

$platforms = "";
foreach ($trophyTitle->platform() as $platform) {
    $platforms .= $platform->value .",";
}
$platforms = rtrim($platforms, ",");
echo $platforms;

And for earned trophies:

foreach ($user->trophyTitles() as $trophyTitle) {
    foreach ($trophyTitle->trophyGroups() as $trophyGroup) {
        foreach ($trophyGroup->trophies() as $trophy) {
            $trophyEarned = $trophy->earned();
            // ...and so on
        }
    }
}

Here's the source of all the methods you can use for $trophy: https://github.com/Tustin/psn-php/blob/master/src/Model/Trophy/Trophy.php

@Argosth
Copy link
Author

Argosth commented Apr 26, 2023

Thank you Ragowit, your Platform method is still giving me the same error, and $trophyGroup->totalTrophyCount(); is giving me this error: Fatal error: Uncaught TypeError: Tustin\PlayStation\Model\Trophy\TrophyGroup::bronze(): Return value must be of type int, null returned

Any ideas how to solve those 2 issues?

Thank you, I'm trying hard to figure it out :)

@Ragowit
Copy link
Collaborator

Ragowit commented Apr 26, 2023

Sorry, I'm at loss. Maybe @Tustin can fill you out when he's around.

@Argosth
Copy link
Author

Argosth commented Apr 26, 2023

No worries mate, you did well and help me out a lot :)

@Argosth
Copy link
Author

Argosth commented Apr 28, 2023

One question, is it possible to get the Trophy Group Name? I'm trying and always return a null. I only managed to get the Trophy Group ID (default, 002, 003 etc).

Thanks :)

@Ragowit
Copy link
Collaborator

Ragowit commented Apr 29, 2023

Check https://github.com/Tustin/psn-php/blob/master/src/Model/Trophy/TrophyGroup.php

You have title(), name() and detail(), it should be one of those.

@Argosth
Copy link
Author

Argosth commented Apr 29, 2023

Check https://github.com/Tustin/psn-php/blob/master/src/Model/Trophy/TrophyGroup.php

You have title(), name() and detail(), it should be one of those.

Hello, about TrophyGroup->name() and detail() are apparently not working, I just managed to get the title() object, but I don't know how to access ["trophyTitleName"] in that object, this is the object returned:

\Tustin\PlayStation\Model\Trophy\UserTrophyTitle::__set_state(array( 'httpClient' => \GuzzleHttp\Client::__set_state(array( 'config' => array ( 'allow_redirects' => false, 'headers' => array ( 'User-Agent' => 'PlayStation/21090100 CFNetwork/1126 Darwin/19.5.0', 'Accept-Language' => 'en-US', ), 'base_uri' => \GuzzleHttp\Psr7\Uri::__set_state(array( 'scheme' => 'https', 'userInfo' => '', 'host' => 'm.np.playstation.com', 'port' => NULL, 'path' => '/api/', 'query' => '', 'fragment' => '', 'composedComponents' => NULL, )), 'handler' => \GuzzleHttp\HandlerStack::__set_state(array( 'handler' => \Closure::__set_state(array( )), 'stack' => array ( 0 => array ( 0 => \Closure::__set_state(array( )), 1 => 'http_errors', ), 1 => array ( 0 => \Closure::__set_state(array( )), 1 => 'allow_redirects', ), 2 => array ( 0 => \Closure::__set_state(array( )), 1 => 'cookies', ), 3 => array ( 0 => \Closure::__set_state(array( )), 1 => 'prepare_body', ), 4 => array ( 0 => \Closure::__set_state(array( )), 1 => '', ), 5 => array ( 0 => \Closure::__set_state(array( )), 1 => '', ), ), 'cached' => \Closure::__set_state(array( )), )), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false, 'idn_conversion' => false, ), )), 'cache' => array ( 'npServiceName' => 'trophy2', 'npCommunicationId' => 'NPWR21008_00', 'trophySetVersion' => '01.00', 'trophyTitleName' => 'Horizon Forbidden West', 'trophyTitleIconUrl' => 'https://psnobj.prod.dl.playstation.net/psnobj/NPWR21008_00/2b1ab462-7ee0-4415-81d8-bf2632f03850.png', 'trophyTitlePlatform' => 'PS5', 'hasTrophyGroups' => true, 'definedTrophies' => array ( 'bronze' => 67, 'silver' => 10, 'gold' => 2, 'platinum' => 1, ), 'progress' => 84, 'earnedTrophies' => array ( 'bronze' => 58, 'silver' => 10, 'gold' => 1, 'platinum' => 1, ), 'hiddenFlag' => false, 'lastUpdatedDateTime' => '2023-04-28T21:52:57Z', ), 'factory' => \Tustin\PlayStation\Factory\TrophyTitlesFactory::__set_state(array( 'httpClient' => \GuzzleHttp\Client::__set_state(array( 'config' => array ( 'allow_redirects' => false, 'headers' => array ( 'User-Agent' => 'PlayStation/21090100 CFNetwork/1126 Darwin/19.5.0', 'Accept-Language' => 'en-US', ), 'base_uri' => \GuzzleHttp\Psr7\Uri::__set_state(array( 'scheme' => 'https', 'userInfo' => '', 'host' => 'm.np.playstation.com', 'port' => NULL, 'path' => '/api/', 'query' => '', 'fragment' => '', 'composedComponents' => NULL, )), 'handler' => \GuzzleHttp\HandlerStack::__set_state(array( 'handler' => \Closure::__set_state(array( )), 'stack' => array ( 0 => array ( 0 => \Closure::__set_state(array( )), 1 => 'http_errors', ), 1 => array ( 0 => \Closure::__set_state(array( )), 1 => 'allow_redirects', ), 2 => array ( 0 => \Closure::__set_state(array( )), 1 => 'cookies', ), 3 => array ( 0 => \Closure::__set_state(array( )), 1 => 'prepare_body', ), 4 => array ( 0 => \Closure::__set_state(array( )), 1 => '', ), 5 => array ( 0 => \Closure::__set_state(array( )), 1 => '', ), ), 'cached' => \Closure::__set_state(array( )), )), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false, 'idn_conversion' => false, ), )), 'platforms' => array ( ), 'withName' => '', 'hasTrophyGroups' => NULL, 'user' => \Tustin\PlayStation\Model\User::__set_state(array( 'httpClient' => \GuzzleHttp\Client::__set_state(array( 'config' => array ( 'allow_redirects' => false, 'headers' => array ( 'User-Agent' => 'PlayStation/21090100 CFNetwork/1126 Darwin/19.5.0', 'Accept-Language' => 'en-US', ), 'base_uri' => \GuzzleHttp\Psr7\Uri::__set_state(array( 'scheme' => 'https', 'userInfo' => '', 'host' => 'm.np.playstation.com', 'port' => NULL, 'path' => '/api/', 'query' => '', 'fragment' => '', 'composedComponents' => NULL, )), 'handler' => \GuzzleHttp\HandlerStack::__set_state(array( 'handler' => \Closure::__set_state(array( )), 'stack' => array ( 0 => array ( 0 => \Closure::__set_state(array( )), 1 => 'http_errors', ), 1 => array ( 0 => \Closure::__set_state(array( )), 1 => 'allow_redirects', ), 2 => array ( 0 => \Closure::__set_state(array( )), 1 => 'cookies', ), 3 => array ( 0 => \Closure::__set_state(array( )), 1 => 'prepare_body', ), 4 => array ( 0 => \Closure::__set_state(array( )), 1 => '', ), 5 => array ( 0 => \Closure::__set_state(array( )), 1 => '', ), ), 'cached' => \Closure::__set_state(array( )), )), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false, 'idn_conversion' => false, ), )), 'cache' => array ( ), 'hasFetched' => false, 'accountId' => '###', )), )), 'hasFetched' => false, 'serviceName' => 'trophy2', ))

@Ragowit
Copy link
Collaborator

Ragowit commented Apr 29, 2023

To get trophy data like title, you can't go via user's TrophyTitles (that will only bring you like trophy earned data for that user).

Let me add more code to my previous reply:

foreach ($user->trophyTitles() as $trophyTitle) {
    // This is for getting data like name and detail, not tied to a user
    foreach ($client->trophies($trophyTitle->npCommunicationId(), $trophyTitle->serviceName())->trophyGroups() as $trophyGroup) {
        // Here we can call $trophyGroup->name(), $trophyGroup->detail(), etc
        foreach ($trophyGroup->trophies() as $trophy) {
            // And here we can reach $trophy->name(), $trophy->detail(), etc
        }
    }
    
    // This is for getting data tied to a user, like earned date
    foreach ($trophyTitle->trophyGroups() as $trophyGroup) {
        foreach ($trophyGroup->trophies() as $trophy) {
            $trophyEarned = $trophy->earned();
            // ...and so on
        }
    }
}

@Argosth
Copy link
Author

Argosth commented May 1, 2023

Thank you very much Ragowit, I think I have everything now, just last questoin, the "earnedRate()" is specific of every player? I thought that was a global var that indicates the rarity of a trophy, or am I wrong?

Thanks :)

@Ragowit
Copy link
Collaborator

Ragowit commented May 1, 2023

I have never used that myself, but I think it's a global var that indicates the rarity of a trophy. Maybe it changes so often so Sony decided to have that data on the user?

@Argosth
Copy link
Author

Argosth commented May 1, 2023

Ok I see, thank you Ragowit :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants