I am trying to retrieve & print User's friends locations. I am using following code:
{scope:'email,friends_location, user_location,publish_stream'});
results += '<div><img src="https://graph.facebook.com/' + friend_data[i].id + '/picture">' + friend_data[i].name + friend_data[i].location + '</div>';
When I am printing value of friend_data[i].location
, it print undefined, when I change this variable to friend_data[i].location.name
then it doesn't work and nothing prints out of it. In User own location I am doing resource.location.name and it work fine.
I have searched many places and tried my code with various combinations but didn't work. Can anyone give me where I am wrong in this code?
Will be very much thankful
After searched few other places, I am answering my own questions, might be helpful for someone in future. Actually I had set correct scope in my question. Probably I wasn't printing the output correctly. But below code definitely works.
Note: location here in the below query refers to current Location.
$userFriend_profile = $facebook->api('/me/friends?fields=name,location&limit=20');
$total = count($userFriend_profile['data']);
for ($i = 0; $i < $total;)
{
if(isset($userFriend_profile['data'][$i]['location']['name']))
{
$city_Value = explode(',',trim($userFriend_profile['data'][$i]['location']['name']));
}
$i = $i + 1;
}