Question

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

Was it helpful?

Solution 2

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;
}

OTHER TIPS

It's all well and good to just write all the necessary permissions:

{scope:'email,friends_location, user_location,publish_stream'});

... but what for?

An access token is generated from the permissions you asked. When building the graph.facebook.com URL corresponding to your Graph query, you don't actually pass any access token. So, your permissions are unused, whatever you did with them before.

To do:

  1. List the permissions (done),
  2. Generate the access token from the permissions (done?),
  3. Pass the access token to your Graph call.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top