Have you in mind to implement the "I like" button for content in your module?. Something link this:
http://www.sociable.es/2010/04/22/facebook-open-graph-y-social-plugins/

CommentFileSizeAuthor
#46 fb_like.zip1.72 KBnancydru

Comments

Dave Cohen’s picture

To add a like button right now, start by enabling the core Drupal for Facebook module.

That's enough to embed facebook social tags in your site. Whether they are <fb:like> or any of the others.

Drupal provides tons of ways to get markup onto a page. You could for example add a block with <fb:like></fb:like> in it. Or do what drupalforfacebook.org does, put a like button in a node's links...

/**                                                                                                              
 * Implementation of hook_link.                                                                                  
 *                                                                                                               
 * Add an XFBML like button to all node pages.                                                                   
 */
function dff_custom_link($type, $object, $teaser = FALSE) {
  if ($type == 'node' && !$teaser) {                           
      $url = fb_scrub_urls(url('node/' . $object->nid, array('absolute' => TRUE)));
      $items['dff_like'] = array(
        'title' => "<fb:like href={$url}></fb:like>",
        'html' => TRUE,
      );
    return $items;
  }
}


In the above code, change "dff_custom" to the name of your module.

The thing is, there are so many ways in Drupal to add markup to a page (blocks, links, node content) I don't know what the best ways are. But I could see a module that makes it easy to add these tags to a page. Such a module would have fb.module as a dependency. And should support <fb:like> as well as the other facebook social tags.

chazz’s picture

How I can enable in 6.x.2.0rc2 please?

Dave Cohen’s picture

This page will give you markup for a like button: http://developers.facebook.com/docs/reference/plugins/like

In the 2.x version, you can use the iframe markup, but not the XFBML. In 3.x you could use either, the XFBML is recommended.

chazz’s picture

Thanks, I used iframe as I find hard to update from 6.x-2 to 6.x-3

BenK’s picture

Subscribing...

carlitus’s picture

Thanks David :)

cientista’s picture

Hi, Firstly, this suite of modules really is awesome, thanks. Will there be any support for fetching facebook user details i.e. email and birthday details? As FB conect terms it - authentication and extended permissions

http://developers.facebook.com/docs/authentication/
http://developers.facebook.com/docs/authentication/permissions

Thanks,
Andy

Carlos Miranda Levy’s picture

Trying to do iframe (using v2.0)...

It works if I do like this (url hardcoded):
<iframe src="http://www.facebook.com/plugins/like.php?href=http://www.tedxsantodomingo.com&amp;layout=standard&amp;show_faces=true&amp;width=200&amp;action=like&amp;font=tahoma&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:200px; height:80px;" allowTransparency="true"></iframe>

But if I do (url generated with alias), I get an error:
<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo fb_scrub_urls(url($_GET['q'], array('absolute' => TRUE))); ?>&amp;layout=standard&amp;show_faces=true&amp;width=200&amp;action=like&amp;font=tahoma&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:200px; height:80px;" allowTransparency="true"></iframe>

Facebook returns an error: "The page at http://www.tedxsantodomingo.com/novedades/i-like could not be reached.", for example.

Any clues? url is properly generated as you can see from the error page, and it works by navigating to it.

Dave Cohen’s picture

I don't know. Have you tried hard-coding that exact URL?

Carlos Miranda Levy’s picture

Here's how I got to work... but only as one fixed I like for the whole site and keep in mind I use Drupal for Facebook 2.x:

  1. Enable the "Facebook social plugins integration module"
    (http://drupal.org/project/fb_social)
  • Note: This module does not work with Drupal for Facebook, but by enabling it we get the proper libraries to be loaded).
  • I added a block visible on all pages with the following code:
    <iframe src="http://www.facebook.com/plugins/like.php?href=http%253A%252F%252Fwww.tedxsantodomingo.com&amp;layout=standard&amp;show_faces=true&amp;width=250&amp;action=like&amp;font=tahoma&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:250px; height:80px;" allowTransparency="true"></iframe>
  • You can see this block on the top center block of http://www.tedxsantodomingo.com

    If I try anyother variation or combination or change the code to have a dynamic url for I like, it fails.

    georgedamonkey’s picture

    This is exactly what I'd like to do. I'd like to have the like button in the link area for nodes (also in the teaser if that's possible). I'm stuck where you say this: 'In the above code, change "dff_custom" to the name of your module.' Which module do you mean? Do I need to create a custom module for this to work? Also, does the code above go into template.php?

    stevesmename’s picture

    Component: User interface » Miscellaneous
    Assigned: Unassigned » stevesmename
    Category: feature » task
    Status: Active » Needs review
    Issue tags: +Facebook Like, +FB Like, +Social Plugin

    Attached is a custom built Facebook Like button module I built. Just install, enable and you have settings on each Content Type to enable and disable the like button. The module supports iframe and fbml (if your theme supports it). This module is not necessary dependent on Drupal for Facebook module.

    An Open Graph module is still needed.

    http://dl.dropbox.com/u/590466/Drupal/modules/fb_like.zip

    jaypark’s picture

    is there a way to get a callback for the like button, or some way to see if a user has clicked it?

    Dave Cohen’s picture

    My understanding is you can't.

    ticici’s picture

    (#3)
    Hello Dave,
    thanks for shared this information. Is it only here written that "...In the 2.x version, you can use the iframe markup, but not the XFBML." , cause I think I read almost everything these days, trying to make that work, and finally came to this comment. And does it still standing?
    I tried to make 6.x-3.x-dev version to work, but I just didn't, and I really need to use XFBML like button, cause I had to catch Like event.
    Any sugestions, clue, idea would be appreciated. Thanks in advance.

    Dave Cohen’s picture

    Assigned: stevesmename » Unassigned
    Status: Needs review » Active

    My understanding is the like button (and all "social" buttons) do not create events. You don't learn when users click these buttons. Facebook offers some statistics for you to analyze, but not events for you to react to in real time. This is certainly true when you present the buttons without an associated application, or when a user has not authorized the app. If the user has authorized the app, maybe there's a way, but I don't know what it is.

    boris mann’s picture

    Shipping an fb_like.module -- either as part of the Drupal for FB bundle or as a separate module with a dependency -- would be a good idea. To Dave's point -- yes, there are a ton of different ways to do the markup. I would start with a block that can be enabled by default (at either a "content top" or "content bottom" region in some theme), as well as a simple one line function that people can embed in themes for advanced uses.

    jaypark’s picture

    you can run an fql to see if the page id is liked by a given user... but this is really sloppy if you need to catch the like event as it occurs. what it does is forces queries, either to your server or fb's (you'd need to query fb to see what the current state is, liked or unliked, even if you saved the results to your server), every time you need to find if a given page or other object id is liked.

    ticici’s picture

    Thanks for your replies.
    Yesterday, I was in a hurry, so I'm not satisfied how I wrote my question. I just wanted to say that I didn't find anywhere else the thing Dave said here (#3) that with 2.x version of module you can't use XFBML buttons. (and that was just what I was trying to do)

    But now just to add this: It seems to me there is an option to catche Like with FB.Event.subscribe (http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe). I think I can do what is needed with it. But for that I need XFBML button, (with Facebook Connect working)
    (and now I'm just trying to set 3.x-dev version to work:)

    Dave Cohen’s picture

    Just to be clear...

    The 3.x branch uses the newest libraries, which allow the newest XFBML tags for like buttons, activity stream, and so on.

    The 2.x branch supports XFBML in general, but not the very latest "social" tags (like buttons, activity stream). And it's not because the 2.x branch is broken, it is because facebook's older javascript libraries does not support the newest tags.

    The primary difference between 2.x and 3.x branches is which version of facebook's libraries they use.

    ticici’s picture

    Ok. Thank you.

    jaypark’s picture

    ticici thanks for that #19 link... that was quite a relief to see.

    rgs’s picture

    subscribing

    adraskoy’s picture

    subscribing

    millions’s picture

    Dave, can you post the module you created for your facebook "Like" buttons on each node for all of us less technically gifted drupalers please?

    Thanks!

    millions’s picture

    I made it work by posting <fb:like width="275"></fb:like> in node.tpl.php in the links section of the full node.

    georgedamonkey’s picture

    Absolutely perfect!

    Thank you!!

    millions’s picture

    Sure thing. I actually ended up changing to post at the top of page.tpl.php so that it shows up on my pages above the teasers. I tried getting it to post on each teaser, and was able to. Unfortunately, it was for the url in the address bar, not the url of each teaser, so moving the code to the top of each page (via page.tpl.php) instead of the bottom of each node worked best for me.

    sp_key’s picture

    I didn't like using a block as the facebook like button would display below all comments making it very hard to notice.
    Not sure about putting it in the nodes links - would that add it on all content?

    I personally added an extra CCK field on all content types that allow commenting, defaulted the value to fb:like /fb:like and prevented editing of the field.

    It works fine this way :)

    RasputinJones’s picture

    >> An Open Graph module is still needed.

    http://drupal.org/node/803512

    Sharing what I wrote earlier...

    westis’s picture

    Like others I'd need a way to select what data is shared to Facebook when a visitor clicks the Like button, such as the image. How can we add Open Graph meta tags to the , as described at http://developers.facebook.com/docs/reference/plugins/like ?

    westis’s picture

    I solved this temporarily by manually adding the tags to the in the page template for that particular node type. With help of the Devel module I was able to see what node fields I was able to use to set the correct image etc.

    toomanypets’s picture

    Posted a custom module for adding Open Graph protocol meta tags here:
    http://drupal.org/node/784904#comment-3582838

    jaypark’s picture

    dave, fb's Vernal indicated during the spring release of the latest social graph api that applications could subscribe to their users graph object updates, so fb would "ping" the application site that the users data changed... how does or can dffb handle these callback pings? that way if we could collect these real time social graph updates for, say, page likes, in a voting api module for fb like or real time analytics.

    jaypark’s picture

    dave, fb's Vernal indicated during the spring release of the latest social graph api that applications could subscribe to their users graph object updates, so fb would "ping" the application site that the users data changed... how does or can dffb handle these callback pings? that way if we could collect these real time social graph updates for, say, page likes, in a voting api module for fb like or real time analytics.

    Dave Cohen’s picture

    Those details are here: http://developers.facebook.com/docs/api/realtime

    I haven't dabbled with this yet, but would like to have support for it, of course.

    There's a similar mechanism where fb_app.module subscribes to the authorize events. I imagine this implemented in a very similar way. I.e. fb_opengraph.module (or whatever it might be called) receives the callbacks, then calls a drupal hook to notify other modules of any information.

    nancydru’s picture

    Here's how I get it to be a part of the node content area.

    function mymodule_node_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
      global $user, $base_url;
      switch ($op) {
        case 'view':
          // Skip teaser view.
          if ($a3 || $node->type != 'blog') {
            return;
          }
    
          // If the Facebook module is present, we can enable a Like button.
          if (module_exists('fb')) {
            $node->content['facebook-like'] = array(
              '#value' => '<fb:like href="' . url("node/$node->nid", array('absolute' => TRUE))
              . '"  layout="box_count" show_faces="false" width="55">'
              . '</fb:like>',
              '#weight' => -10,
              );
          }
    
          return;
      }
    }
    

    @Dave: My customer wants it to read "username likes node-title" rather than "username likes node-url". Is there any way to do that? And is there anyway to know, when someone follows it back to us, where they found the link?

    Dave Cohen’s picture

    I think the correct open graph tags on your page will fix the title: http://developers.facebook.com/docs/opengraph

    There may be something on that page about tracking to click throughs. I recall there is a way to do that but I don't remember exactly where I saw that.

    nancydru’s picture

    Thanks, Dave. That page says only four params are required, but I think your doc page says 6 are required. I will proceed as though FB's docs are more correct.

    nancydru’s picture

    Here's what I'm producing now:

    <meta property="og:description" content="We recently conducted a survey on the Forrester blog to learn about the news sources you use to get interactive marketing" />
    <meta property="og:image" content="http://web-blogs-dev.forrester.com:83/f/b/analystpix/Augie-Ray2.gif" />
    <meta property="og:site_name" content="Forrester Blogs Dev:83" />
    <meta property="og:title" content="New Media Dominates For Interactive Marketing News &amp; Information" />
    <meta property="og:type" content="blog" />
    <meta property="og:url" content="augie_ray/10-12-14-new_media_dominates_for_interactive_marketing_news_information" />
    

    But it still says "You like node-url".

    I'm thinking now that there is some confusion about how it will look on my site vs. how it will look on FB. Guess we'll have to go live to see.

    Spiroc’s picture

    Hello
    @NancyDru
    I have done this easy by installing http://drupal.org/project/opengraph_meta and use the Example Customizations module from DFF plus u need to add extra tag to page.tpl.php

    <meta property="fb:app_id" content="YOUR APP ID" />

    so the head of page.tpl.php looks like this

    <?php
    // $Id: page.tpl.php,v 1.4 2009/07/13 23:52:58 andregriffin Exp $
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
      "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language ?>"xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://opengraphprotocol.org/schema/" >
      <head>
        <title><?php print $head_title ?></title>
        <?php print $head ?>
    	<meta property="fb:app_id" content="YOUR APP ID" />
        <?php print $styles ?>
        <?php print $scripts ?>
        <!--[if lte IE 7]><?php print framework_get_ie_styles(); ?><![endif]--> <!--If Less Than or Equal (lte) to IE 7-->
      </head>
    

    But i have one extra question how to make wen i press the like button to get "username like my canvas app url on my canvas app" i know alot of application who have done this but i can't figure how to be done if some one have idea?

    nancydru’s picture

    I don't have an app id. This is a simple Like button.

    I suspect, we have little control over what shows on our site. The Like button customization only affects what shows on FB itself.

    Spiroc’s picture

    @NancyDru
    You must have facebook app id if u use DFF if no u can use some of this meta tags and again u will get that what u like to see

    
    <meta property="fb:admins" content="user_id" />
    <meta property="fb:page_id" content="your_page_id" />
    <meta property="fb:app_id" content="your_app_id" /> 
    
    nancydru’s picture

    I simply do not know the user's FB user id, nor do I want to set up an application just for a simple stinking Like button.

    Dave Cohen’s picture

    You shouldn't need the application. Having it there will give you additional access to the statistics kept by facebook. So you may want to do that in the future. It doesn't require any additional effort on the part of your users. I don't think the lack of application is the problem with the name/url issue (but I don't know what is the problem)

    Nancy, can you post the og: tags on your page when it works? I wonder why #40 did not work. Maybe because the og:url is not absolute?

    Regarding the canvas urls... when your module generates the url, it can force it to be a canvas url or not, by calling url this way...

    $url = url('my/path', array('absolute' => TRUE, 'fb_canvas' => FALSE)); // generates non-canvas page url.
    

    or

    $url = url('my/path', array('absolute' => TRUE, 'fb_canvas' => TRUE)); // generates canvas page url, only works when $fb_app has canvas page configured.
    
    nancydru’s picture

    StatusFileSize
    new1.72 KB

    When I used the OG tags without an fb:admins, it said I had to have it. I removed the OG stuff entirely and it works. I have no idea why the text changed but it did.

    Here's my module. If you wish to include it, feel free.

    thriftyngreen’s picture

    Why would you need a module ... all due respect. Just curious. Can't you just add a block with the code?

    Dave Cohen’s picture

    You can just add a block with the markup. That's generally what I would do. But many admins appreciate the ease of a module like this (they never even need to know what a like tag looks like).

    They way I see it, the code in modules/fb needs to be very flexible and provide the basics. Other modules such as this can add a layer of user-friendliness for those who want/need it. But I'm not sure where modules like this belong (i.e. inside modules/fb/contrib? Or in there own project on drupal.org?)

    thriftyngreen’s picture

    I hear you dave thanks for the comment. In general I had no problem making OG work. Just added the OG Meta tag module and the html tag code and I was in there. Very simple, as it should be.

    nancydru’s picture

    @Dave: Yes, I put the module in modules/fb/contrib. If you are interested in this, I have a newer version.

    @thiftyngreen: there are settings available in the module for people who like to customize their button without learning how. It's true that one could code a block, but that limits its placement; my module puts it in the node content area. One could even totally avoid the use of the fb module if one cares to learn how to do that.

    thriftyngreen’s picture

    I think one might care to do that cause wow is it slowing my pages down. All around fb makes my pages hang with everything I add from it. Google and FB. but I am not sure the module is the problem as I am only using that for log in at the moment the invite friends feature just took forever to load I disabled it.

    nancydru’s picture

    I have no performance issues with the base FB module and this Like button. But, I don't actually use any Facebook functions, it does little more than load the toolkit. But a performance issue is off topic here, please open it as a new issue.

    Sms2luv’s picture

    So what is the best resort to know if a user liked a page in favebook