Closed (fixed)
Project:
Drupal for Facebook
Version:
5.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
21 Feb 2009 at 21:47 UTC
Updated:
8 Mar 2009 at 20:10 UTC
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
Comment #1
solk commentedComment #2
solk commentedComment #3
Dave Cohen commentedyour code refers to
$facebookin 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_clientis null.Also
fb_app_loadis 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)).Comment #4
solk commentedThank 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
Comment #5
Dave Cohen commentedYes, 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
$fbthat 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.