Im looking to retrieve all of my friends hometowns, I am using similar PHP as that used to retrieve their names. I think the code im using should work but I think because some users havent set a hometown it wont work and says the for each argument is invalid (although this could be completely wrong).
When simply typing in the URL to the web browser I get the following structure:
{
"id": "z",
"friends": {
"data": [
{
"name": "x",
"hometown": {
"id": "x",
"name": "x"
},
"id": "x"
},
Which is then repeated for every user in the friend list, although for friends without a hometown the following is omitted:
"hometown": {
"id": "x",
"name": "x"
},
To retrieve the name and birthday I have used the following PHP:
$response2 = curl_exec($ch2);
$user2 = json_decode($response2, true);
$user3=$user2{'friends'};
$user4=$user3['data'];
echo ("<h2>Friend List</h2><br>");
foreach($user4 as $friend) {
echo $friend["name"] . "<br />" . $friend["birthday"] . "<br /><br />";
}
}
PS I know the variable names arent particularly good but I will change them once ive figured out what im doing for the hometown!
Thanks a lot for any help in advance.