fb_feed_action receives "session key required"

pribeh - April 9, 2009 - 01:41
Project:Drupal for Facebook
Version:5.x-2.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

I've setup the action fb_feed_action for "after saving posts". I've tried posting to my own facebook feed from the website (not canvas page) with a profile that is mapped to my facebook account. I've granted it permission (through its application setting) for it to automatically post to my facebook feed without prompting me. The secret key, api and app id are all entered into the facebook app correctly. Regardless, I get the below after I run cron:

Failed to publish user action: A session key is required for calling this method 453
exception 'FacebookRestClientException' with message 'A session key is required for calling this method'

Anything else I'm missing?

#1

pribeh - April 9, 2009 - 03:35

Ok, so I figured out that I hadn't created a template bundle (a requirement right?). I've setup a template and made sure it's registered at the console, in use by actions (for publishUserAction). This has removed the cron errors however I'm getting nothing from the LF account posted (and that's mapped) to the FB account.

It says in the facebook docs that publishUserAction should post to a user's wall. Does this maybe have something to do with http://drupal.org/node/404824? Should I just wait until showFeedDialog is fully implemented or documented?

#2

pribeh - April 12, 2009 - 15:45

Sorry, still getting this error message with publishUserAction setup as an action (don't know how much of this is related to FB but it only ever shows up if I have publishUserAction setup and cron is run):

# Failed to publish user action: A session key is required for calling this method 453

exception 'FacebookRestClientException' with message 'A session key is required for calling this method' in /var/www/thomas/lc3/sites/all/modules/fb/facebook-platform/php/facebookapi_php5_restlib.php:2708
Stack trace:
#0 /var/www/thomas/lc3/sites/all/modules/fb/facebook-platform/php/facebookapi_php5_restlib.php(813): FacebookRestClient->call_method('facebook.feed.p...', Array)
#1 /var/www/thomas/lc3/sites/all/modules/fb/fb_feed.module(759): FacebookRestClient->feed_publishUserAction('69566799093', '[]', '', '')
#2 /var/www/thomas/lc3/sites/all/modules/actions/actions.inc(99): fb_feed_action_publish(NULL, Array, NULL, NULL)
#3 /var/www/thomas/lc3/sites/all/modules/actions/actions.module(836): actions_do(2, NULL, Array, NULL, NULL)
#4 /var/www/thomas/lc3/modules/node/node.module(519): actions_nodeapi(Object(stdClass), 'insert', NULL, NULL)
#5 /var/www/thomas/lc3/modules/node/node.module(697): node_invoke_nodeapi(Object(stdClass), 'insert')
#6 /var/www/thomas/lc3/sites/all/modules/activitystream/activitystream.module(448): node_save(Object(stdClass))
#7 /var/www/thomas/lc3/sites/all/modules/activitystream/activitystream.module(361): _activitystream_save(Array, Object(stdClass), 'activitystream_...')
#8 /var/www/thomas/lc3/sites/all/modules/activitystream/activitystream.module(333): activitystream_invoke_streamapi(Object(stdClass))
#9 [internal function]: activitystream_cron()
#10 /var/www/thomas/lc3/includes/module.inc(406): call_user_func_array('activitystream_...', Array)
#11 /var/www/thomas/lc3/includes/common.inc(2147): module_invoke_all('cron')
#12 /var/www/thomas/lc3/modules/system/system.module(1765): drupal_cron_run()
#13 [internal function]: system_run_cron()
#14 /var/www/thomas/lc3/includes/menu.inc(418): call_user_func_array('system_run_cron', Array)
#15 /var/www/thomas/lc3/index.php(15): menu_execute_active_handler()
#16 {main}

# warning: Invalid argument supplied for foreach() in /var/www/thomas/lc3/sites/all/modules/user_relationships/plugins/user_relationship_node_access/user_relationship_node_access.module on line 144.

#3

pribeh - April 12, 2009 - 15:49

Just to mention, I am able to see the drupal made template bundle in my facebook tb console (as registered) with the corresponding tokens I setup.

#4

Dave Cohen - April 13, 2009 - 18:33

Are you using the latest actions? The Drupal 6.x compatible ones?

http://drupal.org/project/actions

#5

pribeh - April 13, 2009 - 22:02

oooh. I guess I am. Is DFF 5x not compatible with 2.0 actions? I can't test for another few hours or so. Should I just try installing the 1.0 version?

#6

Dave Cohen - April 13, 2009 - 23:43

No, you should be using the Drupal 6 compatible version. Can you take a screenshot of the action config page?

#7

pribeh - April 14, 2009 - 02:36
AttachmentSize
Picture 1.png 100.11 KB
Picture 2.png 23.35 KB
Picture 4.png 44.82 KB

#8

Dave Cohen - April 14, 2009 - 17:43

I think the error from facebook is correct, because you're not logged in to facebook at the time. If you were on a canvas page, or connected via facebook connect, it would work.

For the app to publish on your behalf, when you're not logged in, you'd need to enable the offline_access extended permission (http://wiki.developers.facebook.com/index.php/Extended_permissions). And the action would have to log in as you. However there's a problem with this last part. Since Facebook Connect features were added to the client API, it sets these unwanted cookies when you try to act on behalf of an offline_access user. And right now I don't have a good fix for that.

Any reason your not using Facebook Connect to do this?

#9

pribeh - April 14, 2009 - 20:29

Ya, I can't seem to get the buttons to show up with facebook connect.

#10

Dave Cohen - April 14, 2009 - 21:13

Sounds like you use IE.

You need to add an xmlns attribute to your html tag, as described http://www.drupalforfacebook.org/node/1106

#11

pribeh - April 14, 2009 - 22:03

Oh, do you mean fbconnect module made by LaNets or simply facebook connect - sorry just working a lot and not quite grasping this. I'm using your modules with facebook connect. Also I'm on mac with saf and FF so no I'm not experiencing that issue even though I've added that xmlns attribute already for any IE users that might use the site. I will try facebook connect again.

Are you suggesting I try fbconnect or try using facebook connect which I'm trying to?

#12

Dave Cohen - April 14, 2009 - 22:40

Within Drupal for Facebook is a module called fb_connect.module. That's what I'm talking about. I would not expect the fbconnect module by LaNets to work alongside Drupal for Facebook.

#13

pribeh - April 14, 2009 - 22:48

Oh, ya. I'm using the one you've provided. Are you then suggesting that there's an automated way to post to the wall simply using facebook connect and I don't have to be using the user publish action?

#14

NigelC - May 1, 2009 - 07:21

Hi Guys,
Dave, I'm finally back looking at your module again. Might even get to some of the upgrades I suggested :)

Anyway I just debugged this and came to post the change but found that it had already been reported.

When offline_access is granted session_expires = 0.

So in fb_user.module the code associated with FB_OP_GET_USER_SESSION needs to change.
Original:
$result = db_query("SELECT * FROM {fb_user_app} WHERE apikey = '%s' and fbu = %d AND session_key_expires > %d", $fb_app->apikey, $fbu, time());
Fix:
$result = db_query("SELECT * FROM {fb_user_app} WHERE apikey = '%s' and fbu = %d AND (session_key_expires = 0 OR session_key_expires > %d)", $fb_app->apikey, $fbu, time());

However, I also had to comment out some code in fb_feed which was checking for a logged in user (and finding one - maybe because I used to have a infinite session setup for the whole app - which offline_access deprecates)... I need to debug whats going on there too.
in fb_feed_action_publish:
// Log into facebook as the current user.
// if ($GLOBALS['fb_app'] && ($fb_app->nid = $GLOBALS['fb_app']->nid))
// We're in a canvas page for the desired app. We're already logged in.
// $fb = $GLOBALS['fb'];
// else {

Facebook are going to kill themselves by breaking everything every 2 months. Its getting crazy. - this offline_access seems to go back to something they had some time ago.

#15

NigelC - May 1, 2009 - 07:58

by the way. Feeds have changed a bit now too, so right now they are not 100% compatible (not having actions links).

But you can edit your templates with a facebook tool. So I am thinking about adding them on drupal then editing them at: http://developers.facebook.com/tools.php?feed

edit: maybe not - looks like the facebook tool only allows adding and deleting.

Nigel

#16

NigelC - May 1, 2009 - 08:05

You know what I really want. I want my application to be able to publish to the users feed only. I want an application action to be published (offline) so that my users all see it on their news feeds but their friends don't see it. I can't seem to do that.

I guess it makes for a spammy interface.

right now they have:
- users friends see actions on news feed when user is USING application
- user sees actions on their PROFILE when I run cron job
- user can see info in a profile box

The one thing missing is the app publishing to the user like it was their friend (ie to users news feed only). Im not even sure if the new streams api supports that.

#17

pribeh - May 1, 2009 - 15:28

Wow. I don't know what facebook is doing but wall publishing is changing daily. Yesterday you could find a user application setting, something along the lines of, 'allow application to post to wall when not logged in'. Now it's changed to 'access my data even when I'm not using the application'. Funny thing is, my girlfriend's account which we're using to help test doesn't display this in her application settings. I posted two images, "mine", is from my facebook user app settings and the other, "girlfriend", from my girlfriend's. Is this because I'm a developer of the app? Or could there be other user privacy settings that interfere with this?

Anyway, so I got my Drupal user account to be able to publish single liners to the wall of my facebook profile after cron jobs without the above code Nigel has posted. At least one more Drupal user (my girlfriends' :) is not able to do this. Could this relate to the above? Probably... Is

[update] trying Nigel's code for FB_OP_GET_USER_SESSION and fb_feed_action_publish. My girlfriend's profile wall now receives posts from the app if she's logged in and posts from the canvas page. However, cron jobs don't get the post on her wall. I'm going to research into why my facebook account has this different ("offline") app setting.

#18

pribeh - May 1, 2009 - 15:29

Forgot to attach the images.

AttachmentSize
girlfriend.png 8.93 KB
mine.png 10.58 KB

#19

pribeh - May 1, 2009 - 15:42

Ok, so I just realized that fb_feed is almost obsolete as a result of the new Open Streams development mentioned in http://drupal.org/node/447610.

I've begun looking into it (http://wiki.developers.facebook.com/index.php/Using_the_Open_Stream_API) and it appears that a full-blown fb_stream.module will have to be made to take over from fb_feed.module - like Dave mentions. I'm curious to try and hack the fb_feed.module for now and see if I can make some headway.

#20

Dave Cohen - May 1, 2009 - 18:37

Facebook changes things all the time. Welcome to the party. Now its feed stuff, because they are introducing the open stream stuff.

Usually feed stories are written directly in response to a user activity. It's a little unusual to need to do it in a cron job. So no surprise that its tricky.

The introduction of facebook connect also causes all sorts of problems for drupal and setting the user of the facebook client api. Because now the client api stupidly sets a bunch of cookies when you change the facebook user. So for example if you do have facebook connect implemented, running this cron job manually via your browser will set cookies that break connect in weird ways. Ugh.

 
 

Drupal is a registered trademark of Dries Buytaert.