Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9261423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T13:08:34+00:00 2026-06-18T13:08:34+00:00

Im trying to return the friend list of a user using a Facebook app

  • 0

Im trying to return the friend list of a user using a Facebook app without using the PHP SDK.
I have managed to return the users name, gender, etc. without using an auth code. Im now trying to return a list of names who are the users friends, all ive managed to do so far is print the array, I cant seem to only print the name as its laid out differently to the users name, gender, etc. which I managed to echo by doing:

$user->name

But when I try that for the friends list it doesnt work and doesnt echo anything at all, I was just wondering if anyone knew how I go about doing this?

Using print_r I get the following:

Array(
[0] => Array ( [name] => Friend's name [id] => x )
[1] => Array ( [name] => Friend's name [id] => x )
[2] =>....)

Until all of the friends have been listed.


 { "name": "Name", 
    "hometown": {
      "id": "Hometown_id", 
      "name": "Hometown"
    }, 
    "id": "Friend_id" }

Above is the structure of the array of each, I think a potential issue is that not everybody has a hometown set which may be why I’m receiving a forEach error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T13:08:35+00:00Added an answer on June 18, 2026 at 1:08 pm

    Given that array structure, it’s pretty simple(in php) to get what you want. I recommend reading from php’s manual on arrays.

    Just try something like this:

    foreach ($array as $inner_array) {
        echo $inner_array['name'] . "<br />";
    }
    

    Aside from that, it would be…

    echo $your_array[0]['name'];
    echo $your_array[1]['name'];
    

    And so on and so fourth..

    Update:

    What you are now looking is not an array, but a javascript object. It is referred to as JSON: Javascript Object Notation.

    You need a special parser to interpret it as an array: json_decode(), which comes shipped with php greater than or equal to 5.2.0. To make the array associative, you must pass a second parameter, a boolean, true. It defaults to false otherwise. An example of usage:

    $json = '{ "name": "Name", 
        "hometown": {
          "id": "Hometown_id", 
          "name": "Hometown"
        }, 
        "id": "Friend_id" }';
    
    $json_arr = json_decode($json,true);
    
    foreach ($json_arr as $key => $var) {
        if (!is_array($var)) {
            if ($key == 'name') {
                echo $var . "<br />";
            }
        }
    }
    

    Update 2:

    foreach ($json_arr as $key => $var) {
        if (!is_array($var)) {
            if ($key == 'name') {
                echo "Name: " . $var . "<br />";
            }
        }
        else {
            if ($key == 'hometown') {
                echo "Hometown: " . $var['name'] . "<br />";
            }
        }
    }
    

    The above should do what you need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building an application for Facebook using Google App Engine. I was trying
Im trying to return a SimpleQuery list that queries a single table and uses
I'm trying to return the most common elements in a list (statistical mode). Unfortunately
I'm trying to return a left child as a pointer I have template <typename
I am trying to return the value by using unix_timestamp function but it behaves
I am trying to return twitter titles based on today's date only. I have
What i am doing is getting friends list from facebook and trying to populate
I have a context processor returning list of users friends. I'd like it to
I have 4 tables... users, friends, articles & article_shares (as in written) A user
I am trying to get friends of a logged facebook user. I use fql,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.