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

  • Home
  • SEARCH
  • 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 843461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:07:51+00:00 2026-05-15T06:07:51+00:00

I’m using the Facebook php-sdk to get the users name and friends, right now

  • 0

I’m using the Facebook php-sdk to get the users name and friends, right now the loading friends part takes about +3 seconds so I wanted to do it via Ajax, e.g. so the document can load and jQuery then calls an external PHP script which loads the friends (their names and their profile pictures). So to do this I did:

    $(document).ready(function() {
      var loadUrl = "http://localhost/fb/getFriends.php" ;
      $("#friends")
       .html("Hold on, your friends are loading!")
       .load(loadUrl);
    });

But I get a PHP error:

Fatal error:  Call to a member function api() on a non-object

If I do this in the same PHP file (so I don’t use Ajax at all to call it) it works fine.

Now I think I understand the reason this is happening, but I don’t know how to fix it. In my main index.php file I have a bunch of init and session code e.g.

    FB.init({
      appId   : '<?php echo $facebook->getAppId(); ?>',
      session : <?php echo json_encode($session); ?>, // don't refetch the session when PHP already has it
      status  : true, // check login status
      cookie  : true, // enable cookies to allow the server to access the session
      xfbml   : true // parse XFBML
    });

So I’m just wondering what is the best way to treat my new separate PHP file getFriends.php in a way where it has access to all PHP/JavaScript session data/variables?

If you haven’t used the Facebook php-sdk I’ll quickly explain what I mean:
Lets say I have index.php and getUsername.php, from index.php I want to retrieve the getUsername.php file via Ajax using .load. Now the problem is getUsername.php needs to access PHP session data/Javascript Init functions which were created in index.php, so I’m thinking of ways to solve this (I’m new to PHP so sorry if this sounds silly) but I’m thinking maybe I could do a POST in jQuery Ajax and post the session data?
Or maybe I could create a PHP class, so something like:

class getUsername extends index{} /*Yes I'm a newbie*/

If you have a look at the php-sdk example.php link posted at the top maybe you’d better understand what variables exactly need to be accessed from a new file.

Also on a different note, I’m using PHP to work out page rendering times and it seems that fetching the users name alone :

// Session based API call.
if ($session) {
  try {
    $uid = $facebook->getUser();
    $me = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
  }
}

Can take a good 4 seconds, is this normal? Once I get the users details is it good to cache it or something? -Speed isn’t as important right now, for now I’m just trying to figure out this Ajax-separating php files thing.

Woah this is a long post.

Thanks very much for your time.

  • 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-05-15T06:07:52+00:00Added an answer on May 15, 2026 at 6:07 am

    First of all, sorry if I misunderstood you,

    There is a way to send data trough the load function:

    $("#target").load("test.php", { 'choices[]': ["Jon", "Susan"] } );
    

    or

        $("#target").load("test.php", {limit: 25}, function(){
       alert("The last 25 entries in the feed have been loaded");
     });
    

    Hope this helps…

    PS: It’s completely normal for the page to take a few seconds to respond… (I refer to the FB API only)

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

Sidebar

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.