User's country
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.
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().
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 ?
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;
}
}
I wrote more or less the same code ... I also tried your code (and corrected line 4 ($user with $userSearchResult)). Still nothing.
Does it happen for all users you're searching for, or just one specific?
All users
If i use a var_dump ($userSearchResult), I can see the country in [cache] but can't access it.
I'm at loss, dunno what to try next or how to solve it.
Thank you for trying. 👍