Closed (fixed)
Project:
Drupal for Facebook
Version:
6.x-2.0-beta2
Component:
Facebook Connect
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
16 Feb 2010 at 13:58 UTC
Updated:
6 Apr 2012 at 04:32 UTC
Is there a way to hook the facebook callback handling? As I understand, when someone posts a comment using fb:comments, facebook calls our callback URL with a few parameters, including the xid of the comments. I want to use this to award users points for commenting with something like the following:
if (isset($_REQUEST['fb_sig_xid']))
{
//do some cool stuff
}
Comments
Comment #1
mikerasmussen commentederr...I think it should be:
Comment #2
Dave Cohen commentedIf I were doing this, I'd use the callbackurl attribute, and set it to something like
url(FB_APP_EVENT_PATH . '/my_comment_event')Then, implement
hook_fb($op, $data, &$return). $op will beFB_APP_OP_EVENT, and $data will contain$data['fb'],$data['fb_app']and$data['event_type'].hook_fb will be called for other $ops and other events, like when a new user authorizes, so check that
$data['event_type'] == 'my_comment_event'before handling the event. The$returnparameter does not matter for FB_APP_OP_EVENT.Another option would be for you to implement your own callback, using hook_menu() and so on. Please let us know whether this works or what you end up with.
Comment #3
mikerasmussen commentedok, I am stumped again. As it turns out, this data is not passed back via the callback, but rather you need to register a javascript handler to listen for a comment post:
This works when I add it to the page, but now I have the variable I need "comment.user" in javascript, how the heck do I call my PHP function with this? I looked at some AJAX libraries like PHPLiveX that claim to make it possible to call PHP from within javascript, but I couldn't get it to work for whatever reason....
Comment #4
mikerasmussen commentedok, I got this working in the following way. I had to add the following to the bottom of my page.tpl.php for my theme (there is probably a more elegant way to add this):
Notice the call to $.get with the comment.user as an "argument" attached to the path.
Then I added the following in my custom module source:
and the following _menu hook that registers the above function as the callback for the /comments/award url...
Only thing is that I have to refresh to get it to show up, so I am doing something wrong still, but for now I think I can live with that. Any ideas?
Comment #5
Dave Cohen commentedJavascript in general is a pain... and facebook tends to make it only more so. So, the fact that you got anything working... pat yourself on the back.
You may be able to clean things up by searching Drupal's docs about how to add javascript, and looking to other modules for examples.
It's bad form to add javascript to page.tpl.php. Instead, look at fb_connect.module as an example. See fb_connect_fb() as an example of hook_fb() that adds some javascript to every page. Your module could do something very similar. For example, fb_connect_require_feature('Comments') would get that require features function. Sorry, I haven't worked with that specifically, yet. So I encourage you to continue sharing here whatever you end up with.
Comment #6
13rac1 commentedClosing old issue.