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

User's country

Open Reuns opened this issue 4 months ago • 9 comments

Hi there !

I'm trying to get a user's country but I always have nothing.

From this : $query = $client->users()->search($psnId); $query->current()->accountId(); I get the accountId. 👍 $query->current()->country()) I get nothing : string(0) "" 👎

What am I doing wrong ? @Ragowit any idea ?

Thanks for your help.

Reuns avatar Aug 29 '25 23:08 Reuns

First, there's an error in your code or just a typo?

$query->current()->country()) should be $query->current()->country(); (; is missing at the end).

Other then that, it looks fine as far as I can tell. Never used current() myself, but I don't think that's the problem.

I once had a rare bug where I only got data from the first call, can you try swap around like this?

$query->current()->country(); // Do you get country now?
$query->current()->accountId(); // ...but accountId is nothing?

If you get country now but not accountId, try:

$user = $query->current();
$user->accountId();
$user->country();

On further note so is country information only retrieved via search() and not find(), but it looks like you're using search().

Ragowit avatar Aug 30 '25 09:08 Ragowit

Thanks for your answer. Yes it is a typo when I adapted my copy/paste for here.

I'm using search (), and the country still doesn't work, even when I swap. And the $user = $qu... doesn't work neither.

maybe the current() method is the issue. I'll try to find an other way than current () ... maybe you have the other way to share ?

Reuns avatar Aug 30 '25 18:08 Reuns

This is my code that I use.

$userCounter = 0;
foreach ($client->users()->search($psnId) as $userSearchResult) {
    if (strtolower($userSearchResult->onlineId()) == strtolower($psnId)) {
        $country = $user->country();
        break;
    }

    // Limit to the first 50 search results
    $userCounter++;
    if ($userCounter >= 50) {
        break;
    }
}

Ragowit avatar Aug 30 '25 19:08 Ragowit

I wrote more or less the same code ... I also tried your code (and corrected line 4 ($user with $userSearchResult)). Still nothing.

Reuns avatar Aug 30 '25 19:08 Reuns

Does it happen for all users you're searching for, or just one specific?

Ragowit avatar Aug 30 '25 19:08 Ragowit

All users

Reuns avatar Aug 30 '25 19:08 Reuns

If i use a var_dump ($userSearchResult), I can see the country in [cache] but can't access it.

Reuns avatar Aug 30 '25 19:08 Reuns

I'm at loss, dunno what to try next or how to solve it.

Ragowit avatar Aug 30 '25 20:08 Ragowit

Thank you for trying. 👍

Reuns avatar Aug 30 '25 21:08 Reuns