Similar feature requests have been made previously:
http://drupal.org/node/1440254
http://drupal.org/node/1420710

I intend to attach a patch that creates a new function, fbouath_request(). It will simply accept the $action_name that should be executed, and will take care of acquiring the access token and redirecting the user to the facebook authorization page.

To keep the code DRY, I plan to break fboauth_action_link_properties() into smaller units that can be shared by a new fboauth_request() function.

Comments

grasmash’s picture

grasmash’s picture

Status: Active » Needs review

Switching to needs review.

quicksketch’s picture

This looks pretty good, but I'm questioning the value being provided here. The two links you included:

#1440254: Performing graph queries in the background with access token, not as an action
#1420710: Initiating an action when user browses to a page

The first one isn't helped by this feature request. Since FBOAuth doesn't let you execute anything "in the background".

The second request is only helped marginally, as was found in that issue, it's only 3 lines of code to execute the drupal_goto() yourself. The creation of a function that wraps around drupal_goto() may lead developers to believe they could execute the code inline, but certainly wouldn't work. For example most developers would expect they could do something like this:

function my_menu_callback() {
  $friends = fboauth_request('import_friends');
  foreach ($friends as $friend) {
    // Do something with $friend.
  }
}

But this obviously isn't going to work because fboauth_request() doesn't return a value. In fact if you put *any* code below fboauth_request(), it would never get executed. I don't think the name of the function makes clear its purpose. The naming makes me think it's going to operate like drupal_http_request(), not a drupal_goto().

grasmash’s picture

Agreed on both points.

1) The name of the function could be clearer. Maybe something like fboauth_execute_action_redirect().
2) This doesn't directly address either of the mentioned issues. It's only obliquely related.

However, I found the changes in this patch to be useful in two use cases:
1) Creating a menu callback that will execute an action.
2) Creating a $form['submit'][] handler that will execute an action.

Beyond that, splitting out the fboauth_build_query() and fboauth_build_scope() functions made it easier for me to extend fboauth in my own custom modules, and to better understand steps involved in building the link.

Pedro Lozano’s picture

I've created a sandbox project to permanently store the access_tokens, which can be used to execute facebook api call programatically without user interaction our without having to redirect the user to facebook for executing an action.

http://drupal.org/sandbox/pl2/1600932

@quicksketch I'd appreciate your feedback on this since I'm not sure about the security implications that storing access_tokens may have and how this fits with facebook's policies about api calls.

I've also developed a module that makes use of the token store to post to facebook from the node form: http://drupal.org/sandbox/pl2/1600946

jacobpov’s picture

Will this be stable any time soon ?

mototribe’s picture

sorry, wrong post, please delete.

norman.lol’s picture

Issue summary: View changes

At least for POST queries like a publish_actions https://www.drupal.org/node/1420710
has helped me a lot. I triggered following code from a custom form submit where I also prepared some $_SESSION values I then could use as post message, picture or what so ever.

  // Get link array from fboauth module for making the FB request.
  $fboauth_link_array = fboauth_action_link_properties('CUSTOM_FBOAUTH_POST_ACTION');
  // Build the fboauth URL.
  $full_fboauth_url = url($fboauth_link_array['href'], array('absolute' => TRUE, 'query' => array($fboauth_link_array['query'])));
  // Fire!
  drupal_goto($full_fboauth_url);