Hi,

I hope I haven't missed anything in any documentation about this, but I was wondering if someone could point me in the right direction for accessing some basic data from the fb module via my own content type (made with CCK).

I am new to drupal and I've been reading around, but nothing easy jumps out at me and don't want to head off in the wrong (hard) direction only to find out later what I should have done.

Right now I just want to get the facebook user id and use it in a ConTemplate template. I am pretty sure I can get this info from the drupal username as a hack, but I would like to do this the right way so that when I want something more complicated I know how to do it.

Any ideas?

Comments

Dave Cohen’s picture

I'm not sure how this meshes with contemplate or cck, but DFF provides a function fb_get_fbu() which takes a drupal uid and returns the corresponding Facebook id. (In code I call Facebook id "fbu").

If you call that method when not serving a canvas page, you also need to pass in an fb_app object, which you can get from fb_get_app().

I'm not sure if you were trying to avoid coding to do this. Right now, there are only these functions.

NigelC’s picture

Thanks Dave,

This is obvious now that I have read some more about themes, cck and contemplate and then read over your theme to see how you've done things.
In the interest of any future readers I have decided that ConTemplates is the wrong approach (as other people seem to also indicate). Themes are the way to go.

Before I go on... thanks to:
Agaric Design: http://agaricdesign.com/theming-cck-the-agaric-way
Drupal: http://drupal.org/node/62462
and CCK/theme/README.txt
(and of course Facebook for Drupal - great work Dave, its been 4 days and I almost have a working app)

So you can override the CCK html rendering by creating a themes/fb_fbml/node-content_type.tpl.php template (content_type is the name of your content type). Maybe you will want to have a different test content_type to initially publish a CCK field. That way you can get the html format and adjust as you like.... or use something like print $field_my_field[0]['view'];

Then include any new internal facebook variables by adding them to fb_fbml/template.php function _phptemplate_variables (in hook = node section)
You can then use the new variable $variable in the node-content_type.tpl.php.

Easy when you finally dig into how this stuff works. See CCK/theme/node-content_example.tpl.php for an example.

You will loose some of the functionality of the Content Types > Display Fields, but that kind of goes without saying since you are creating your own template.
However note that CCK has a CCK/theme/README.txt which explains how to just override a CCK field template if thats all you want to do. This way you can keep the Display Fields "Administration" control (if your content writers need some control but can't write php) while still changing the resulting html.

Oh, By the way. Any hints on a good way to modify your template.php without causing headaches when upgrades come along? Im thinking about calling a function in another php file, so that the changes to your file are minimal, any better or standard ways of doing this?

Dave Cohen’s picture

Status: Active » Fixed

Oh, By the way. Any hints on a good way to modify your template.php without causing headaches when upgrades come along? Im thinking about calling a function in another php file, so that the changes to your file are minimal, any better or standard ways of doing this?

In Drupal 6 this is easier as you can use sub-themes. In 5, you're stuck dealing with it. Either make a copy of fb_fbml and put all your changes in the copy. Or get fancy with subversion or other source code control; use the original fb_fbml as a vendor branch and make your changes in a custom branch.

NigelC’s picture

Thanks. that might work well.

If anyone is interested getting the fb_app and fbu in template.php is easy (once you figure out that $vars['uid'] is the article author, not the viewer)

$search = array('apikey' => 'yourkey');
or
$secret = array('nid' => $your_fb_app_node_id);
$fb_app = fb_get_app($search);
$fbu_viewer = fb_get_fbu($user->uid,$fb_app);

by the way - there is some code in there for viewing the author's picture.... but I can't see how it would work without getting the $fb_app as I have shown above.

NigelC’s picture

Version: 5.x-1.x-dev » 5.x-2.x-dev

Updated Version to 2.x.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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