Hi,
I am using the 2.x code and most things are alright.

I can use SOME Facebook functions, such as getInfo, photos_get and photos_getTags
but I can't seem to use other functions such as fql_query, photos_getAlbums and other "newer" functions.

Tha client libs are where they suppose to be (that's why I can use the basic functions) and I checked and saw that
the newer functions are present there in the .php file.

The error I get is:
Fatal error: Call to a member function photos_getAlbums() on a non-object

for the code:

 $fb_app = fb_app_load(1);
     $fb = fb_api_init($fb_app, FB_FBU_ANY);
    
   if ($fb) {
    $albums = $facebook->api_client->photos_getAlbums($uid, NULL); 
  }

By the way, the following similar code works great:

 $fb_app = fb_app_load(1);
     $fb = fb_api_init($fb_app, FB_FBU_ANY);
    
   if ($fb) {
    $albums = $facebook->api_client->photos_get($uid, '',''); 
  }

Any help?

Comments

solk’s picture

Title: Some function are ok but some get: Fatal error: Call to a member function photos_getAlbums() on a non-object » Some fb api functinos work but some are not (Fatal error: Call to a member function photos_getAlbums() on a non-object)
solk’s picture

Title: Some fb api functinos work but some are not (Fatal error: Call to a member function photos_getAlbums() on a non-object) » Some api functions work but some are not (Fatal error: Call to a member function photos_getAlbums() on a non-object)
Dave Cohen’s picture

Status: Active » Fixed

your code refers to $facebook in places where I would expect to see $fb. So, I'm surprised that any of it works. Maybe you're using some other module that defines $facebook. Your PHP message is pretty clear that your calling a function on a non-object, implying $facebook->api_client is null.

Also fb_app_load is a Drupal hook and should only be called by Drupal. You're calling it wrong, too. Instead, use $fb_app = fb_get_app(array('nid' => 1)).

solk’s picture

Thank you, that did work (I can't believe I didn't notice that myself...).
I do wander how come the other code worked.

btw, is that a proper way to initialize the facebook object when not viewing a page through the canvas?

Thank you

Dave Cohen’s picture

Yes, that is one proper way. I think you used code from elsewhere in the modules as an example. On canvas pages, there is a global $fb that can be used. Depending on the functions you plan to call, you may need an active user session. In that case pass a facebook id instead of FB_FBU_ANY. Typically, the user will have had to enable the extended permission that prevents sessions from expiring for your app.

When using facebook connect, you can use fb_connect_app_init (note: I will rename that function fb_connect_api_init, to be consistent with fb_api_init). I am thinking of adding a global when users are connected via fbConnect, similar to the global used for canvas pages, but its not in there yet.

This interface may seem complicated, but it allows some cool things, like using the facebook API for two different apps during a single request.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.