I tried both Drupal for Facebook version 7.3.x and 7.4.x

7.3 Had the option to store the user access token in the fb_user_app table. Then we had the oportunity to use different token for offline access (for example from a cron)

7.4 Doesn't have this table anymore, instead we have a fb_token table that appear to work completely different. I'm not sure but the current fb_token is used to store specific token like app token or other specific user token.

Then my question is if possible to have a table for store user token. We know that new tokens are only valid for 2 hours but there is a method to extend, I guess you're using it in fb_admin_long_lived_token.

I wrote a little module in my own for store those in a separate table, but not sure if I'm handle tokens correctly.

What do you think?

CommentFileSizeAuthor
#5 fb_user_token.zip2.81 KBdariogcode

Comments

sonicthoughts’s picture

Would definitely like to understand storage of access tokens in 7.4 - I think most new implementers are using 7.4 now.

Dave Cohen’s picture

It does not store regular user tokens on its own. Most apps don't need it, and most tokens will fail after the user logs out. I don't want to bake into modules/fb any behavior that might violate facebook's policies.

If your app is adhering to facebook's policies and wants to store the token for later use, call fb_token_save(). There's a corresponding fb_token_load(), but it is not uid aware. In modules/fb, the uid aware code is all in fb_user. That module could have a helper function, i.e. fb_user_token_load() which could take a uid and return a token. If anyone want to make a patch with that function, I'd review it. Although it may be unnecessary as fb_user.module include the user's facebook id (called fbu) in it's hook_user_load().

sonicthoughts’s picture

Wondering if / how this might integrate with fb_autopost This module uses the Facebook SDK and creates entities for posts, events, etc. This is very handy for system builders (like me) to use in rules. For example, I'm posting a CiviCRM event to facebook.

I'd also like the user to be able to selectively post events they attend and register with their facebook module. Is the above method the best way for the two modules to share the same token? Love the capabilities of both modules (entity / rule support and user login)

I loaded 7.4 but hard to tell it stands from a production standpoint. I know it is different from earlier versions, and not fully implemented but not sure what is in/out/different....

thx for quick response?

Dave Cohen’s picture

I don't have experience with that particular module. While modules/fb tries to coexist peacefully with other facebook modules, they rarely return the favor.

modules/fb 4.x includes an fb_post.module which does something very similar. fb_post is fairly lightweight, and typically you'll implement a hook in order to tailor your content into the data structure that facebook expects.

modules/fb *does* remember an access token if it configured for cross-posting to a facebook page. It does not remember typical end user's connect tokens. It does not try to interact with facebook for those users when they are not logged in.

dariogcode’s picture

StatusFileSize
new2.81 KB

For those interested here is a tiny module I'm using to store user token (for offline access), it is for a personal site so have tons debug and is provide with no guarantee, but you can have an idea how to store token. It also have the "extend" token call for have a long token (60 days?)