You are here

README.txt in Facebook OAuth (FBOAuth) 6

Same filename and directory in other branches
  1. 7.2 README.txt
  2. 7 README.txt
Description
-----------
This module provides basic Facebook connect ability through the Facebook OAuth
API. While out of the box it only provides functionality for logging users into
your site, it can be extended with various actions (such as a contact import) through its APIs.

Requirements
------------
Drupal 6.x

Installation
------------
1. In order for your site to use Facebook Connect you must register an
   application on Facebook. Visit https://www.facebook.com/developers/apps.php
   and create a new application, usually simply the name of your website such as
   "example.com".

2. While setting up your application, set the "Deauthorize Callback" to
   "http://example.com/fboauth/deauthorize". This will allow Facebook OAuth to
   cleanup user information if the application is disconnected from the Facebook
   site.

3. Copy the entire fboauth directory the Drupal sites/all/modules directory.

4. Login as an administrator. Enable the module in the "Administer" -> "Site
   Building" -> "Modules"

5. Configure the Facebook OAuth module settings under "Administer" -> "Site
   configuration" -> "Facebook OAuth settings". Copy and paste the App ID and
   App Secret from your newly created Facebook application's settings.

   Note that it is highly recommended to request access to the Facebook user's
   e-mail address so that normal Drupal functionality (the password reset for
   example) will continue to work even if the user has logged in with Facebook.
   This option is enabled by default.

   If you have installed the Profile module, you may also map information
   between your Profile fields and Facebook's available fields.

6. You can enable the Facebook connect button either by enabling the included
   Facebook OAuth block under "Administer" -> "Site building" -> "Blocks", or
   you can print out the link manually in your theme with the following code:

   <?php print fboauth_action_display('connect'); ?>

7. Click on the Facebook Connect button to bind your Facebook account together
   with your user account. If you are logged out when you connect for the first
   time, a new account will be created for you. If you are logged in when you
   click the connect button, your existing account will be associated with your
   Facebook login.

If you just want to connect your site with Facebook, you do not need to read any
further. The module is now configured and the user can log into your site. If
you'd like to customize the display of your Facebook connect link or query other
information from Facebook you may read the sections on Theming and the APIs.

Theming
-------
The Facebook OAuth module includes default theming connecting to Facebook. You
can override this output (or any other output in Facebook OAuth) by doing the
following:

1. Copy the theme_fboauth_action__connect() function from fboauth.module file.

2. Paste this function into your template.php file in your theme.

3. Change the function's output to match your liking (such as adding a class or
   rel attribute to the link).

4. Clear the Drupal theme cache at admin/settings/performance. Click the "Clear
   all caches" button at the bottom of the page.

Or an alternative if you don't want to use the fboauth_action_display() function
to print out the link, you can simply grab the link properties from the
fboauth_action_link_properties() function and output the link manually:

<?php
$link = fboauth_action_link_properties('connect');
print l(t('Connect'), $link['href'], array('query' => $link['query']));
?>

API Integration
---------------
The Facebook OAuth module provides an API for executing queries against
Facebook's vast store of user data. However in order to use this API it is
important to understand the basic concepts of OAuth. In short, the user (and
only the user) is capable of granting your site access to query information
against Facebook. The user is also only able to do this on Facebook.com, so any
requests to query against Facebook must first redirect the user to Facebook
where they can grant access. The full workflow looks like this:

1. The user clicks on a link (such as the Facebook Connect button) that sends
   the user to Facebook. If the link is requesting permissions that the user has
   not yet granted, the user is prompted to allow access. After the user has
   granted access, or if the user granted access previously, the user is 
   redirected back to your site.

2. When the user is redirected back to your site, Facebook sends along an access
   "code". Your site then takes this access code and does a server-side request
   to Facebook's API servers. Facebook's servers return an access "token" to
   your server. This token is valid for a short amount of time and allows you to
   access the information to which the user granted you access.

3. Your site can now execute queries against the user's Facebook information
   while the token is valid. Because this token only lasts a short amount of
   (about 6 hours usually), it's safest to always request access from Facebook
   before every data import session (by having the user click the link), which
   will renew the existing token or generate a new one.

So all in all, this is a lot of back and forth between your site and Facebook
before you can query a user's information. Fortunately the Facebook OAuth module
handles all of the back and forth and gives you the necessary access token. All
you need to do is register a function with Facebook OAuth and it does all the
work of getting you access. You just write the query and import necessary
information.

Integrating with Facebook OAuth requires writing a module (though it can just be
a few lines). If you help writing a module, the Examples module is a good
introduction to writing modules: http://drupal.org/project/examples.

In your module file, you first need to implement hook_fboauth_actions() such as 
this:

<?php
/**
 * Implements hook_fboauth_actions().
 */
function mymodule_fboauth_actions() {
  // Give each action a unique key, such as "mymodule_photo_import" for a photo
  // import. This function should begin with the name of your module.
  $actions['mymodule_photo_import'] = array(
    // Give you action a human-readable name. This will be used when showing
    // the user a link to start this action.
    'title' => t('Import my Facebook photos'),

    // Specify the name of your callback function that contains the import.
    'callback' => 'mymodule_fboauth_action_photo_import',

    // Specify permissions you need to do this action. See the Facebook API for
    // a list: http://developers.facebook.com/docs/authentication/permissions/
    'permissions' => array(
      'user_photos', // Gets access to a user's photos.
    ),

    // Optionally specify a file that contains your callback function. If you
    // put your callback function in the .module file, this is unnecessary.
    // 'file' => 'mymodule.inc',

    // Optionally define a theme function for printing out your link (not
    // including the "theme_" prefix). If you use this option, you must register
    // this function in hook_theme(). If you don't use this option, the link
    // will be output with the theme_fboauth_action() function or the automatic
    // suggestion theme_fboauth_action__[action_name]().
    // 'theme' => 'mymodule_fboauth_action',
  );
  return $actions;
}
?>

Then write your function specified as the "callback" in the above hook.

<?php
/**
 * Facebook OAuth action callback; Import a user's Facebook photos.
 */
function mymodule_fboauth_action_photo_import($app_id, $access_token) {
  // Query against the Facebook Graph API. See the Facebook API for a list of
  // commands: http://developers.facebook.com/docs/reference/api/
  $result = fboauth_graph_query('me/photos', $access_token);
  foreach ($result['data'] as $photo) {
    // Import into Drupal.
  }

  // Optionally set a completion or error message.
  drupal_set_message(t('Import complete!'));

  // Optionally return a path to which the user will be redirected. If not set
  // the path in the $_REQUEST['destination'] variable will be used. If there
  // is no path at all specified, the user will be redirected to the homepage.
  return 'mymodule/import-complete';
}
?>

Now to get the user to actually execute this action, you need to link to
Facebook so that the user can grant the necessary access. You can do this with
the utility function fboauth_action_display(). Our example action was keyed as
"mymodule_photo_import", so we would print the link like this:

<?php print fboauth_action_display('mymodule_photo_import'); ?>

Now when the user clicks on the output link, they will have the option of
granting access to the requested information. If they approve, your callback
function will be executed.

More information about Facebook OAuth's other hooks are documented in the 
fboauth.api.php file included with this module.

Deauthorization or access revocation from Facebook.
---------------------------------------------------
If a user revokes access to the application from the Facebook side, and the
application has provided a Deauthorize callback URL (see Install step 2 above),
Facebook will notify your site that the user has disconnected their account from
your site.

A hook is provided to allow other modules to respond to this event as well - see
hook_fboauth_user_deauthorize() in fboauth.api.php file.

Support
-------
Please use the issue queue for filing bugs with this module at
http://drupal.org/project/issues/fboauth?categories=All

File

README.txt
View source
  1. Description
  2. -----------
  3. This module provides basic Facebook connect ability through the Facebook OAuth
  4. API. While out of the box it only provides functionality for logging users into
  5. your site, it can be extended with various actions (such as a contact import) through its APIs.
  6. Requirements
  7. ------------
  8. Drupal 6.x
  9. Installation
  10. ------------
  11. 1. In order for your site to use Facebook Connect you must register an
  12. application on Facebook. Visit https://www.facebook.com/developers/apps.php
  13. and create a new application, usually simply the name of your website such as
  14. "example.com".
  15. 2. While setting up your application, set the "Deauthorize Callback" to
  16. "http://example.com/fboauth/deauthorize". This will allow Facebook OAuth to
  17. cleanup user information if the application is disconnected from the Facebook
  18. site.
  19. 3. Copy the entire fboauth directory the Drupal sites/all/modules directory.
  20. 4. Login as an administrator. Enable the module in the "Administer" -> "Site
  21. Building" -> "Modules"
  22. 5. Configure the Facebook OAuth module settings under "Administer" -> "Site
  23. configuration" -> "Facebook OAuth settings". Copy and paste the App ID and
  24. App Secret from your newly created Facebook application's settings.
  25. Note that it is highly recommended to request access to the Facebook user's
  26. e-mail address so that normal Drupal functionality (the password reset for
  27. example) will continue to work even if the user has logged in with Facebook.
  28. This option is enabled by default.
  29. If you have installed the Profile module, you may also map information
  30. between your Profile fields and Facebook's available fields.
  31. 6. You can enable the Facebook connect button either by enabling the included
  32. Facebook OAuth block under "Administer" -> "Site building" -> "Blocks", or
  33. you can print out the link manually in your theme with the following code:
  34. 7. Click on the Facebook Connect button to bind your Facebook account together
  35. with your user account. If you are logged out when you connect for the first
  36. time, a new account will be created for you. If you are logged in when you
  37. click the connect button, your existing account will be associated with your
  38. Facebook login.
  39. If you just want to connect your site with Facebook, you do not need to read any
  40. further. The module is now configured and the user can log into your site. If
  41. you'd like to customize the display of your Facebook connect link or query other
  42. information from Facebook you may read the sections on Theming and the APIs.
  43. Theming
  44. -------
  45. The Facebook OAuth module includes default theming connecting to Facebook. You
  46. can override this output (or any other output in Facebook OAuth) by doing the
  47. following:
  48. 1. Copy the theme_fboauth_action__connect() function from fboauth.module file.
  49. 2. Paste this function into your template.php file in your theme.
  50. 3. Change the function's output to match your liking (such as adding a class or
  51. rel attribute to the link).
  52. 4. Clear the Drupal theme cache at admin/settings/performance. Click the "Clear
  53. all caches" button at the bottom of the page.
  54. Or an alternative if you don't want to use the fboauth_action_display() function
  55. to print out the link, you can simply grab the link properties from the
  56. fboauth_action_link_properties() function and output the link manually:
  57. $link = fboauth_action_link_properties('connect');
  58. print l(t('Connect'), $link['href'], array('query' => $link['query']));
  59. ?>
  60. API Integration
  61. ---------------
  62. The Facebook OAuth module provides an API for executing queries against
  63. Facebook's vast store of user data. However in order to use this API it is
  64. important to understand the basic concepts of OAuth. In short, the user (and
  65. only the user) is capable of granting your site access to query information
  66. against Facebook. The user is also only able to do this on Facebook.com, so any
  67. requests to query against Facebook must first redirect the user to Facebook
  68. where they can grant access. The full workflow looks like this:
  69. 1. The user clicks on a link (such as the Facebook Connect button) that sends
  70. the user to Facebook. If the link is requesting permissions that the user has
  71. not yet granted, the user is prompted to allow access. After the user has
  72. granted access, or if the user granted access previously, the user is
  73. redirected back to your site.
  74. 2. When the user is redirected back to your site, Facebook sends along an access
  75. "code". Your site then takes this access code and does a server-side request
  76. to Facebook's API servers. Facebook's servers return an access "token" to
  77. your server. This token is valid for a short amount of time and allows you to
  78. access the information to which the user granted you access.
  79. 3. Your site can now execute queries against the user's Facebook information
  80. while the token is valid. Because this token only lasts a short amount of
  81. (about 6 hours usually), it's safest to always request access from Facebook
  82. before every data import session (by having the user click the link), which
  83. will renew the existing token or generate a new one.
  84. So all in all, this is a lot of back and forth between your site and Facebook
  85. before you can query a user's information. Fortunately the Facebook OAuth module
  86. handles all of the back and forth and gives you the necessary access token. All
  87. you need to do is register a function with Facebook OAuth and it does all the
  88. work of getting you access. You just write the query and import necessary
  89. information.
  90. Integrating with Facebook OAuth requires writing a module (though it can just be
  91. a few lines). If you help writing a module, the Examples module is a good
  92. introduction to writing modules: http://drupal.org/project/examples.
  93. In your module file, you first need to implement hook_fboauth_actions() such as
  94. this:
  95. /**
  96. * Implements hook_fboauth_actions().
  97. */
  98. function mymodule_fboauth_actions() {
  99. // Give each action a unique key, such as "mymodule_photo_import" for a photo
  100. // import. This function should begin with the name of your module.
  101. $actions['mymodule_photo_import'] = array(
  102. // Give you action a human-readable name. This will be used when showing
  103. // the user a link to start this action.
  104. 'title' => t('Import my Facebook photos'),
  105. // Specify the name of your callback function that contains the import.
  106. 'callback' => 'mymodule_fboauth_action_photo_import',
  107. // Specify permissions you need to do this action. See the Facebook API for
  108. // a list: http://developers.facebook.com/docs/authentication/permissions/
  109. 'permissions' => array(
  110. 'user_photos', // Gets access to a user's photos.
  111. ),
  112. // Optionally specify a file that contains your callback function. If you
  113. // put your callback function in the .module file, this is unnecessary.
  114. // 'file' => 'mymodule.inc',
  115. // Optionally define a theme function for printing out your link (not
  116. // including the "theme_" prefix). If you use this option, you must register
  117. // this function in hook_theme(). If you don't use this option, the link
  118. // will be output with the theme_fboauth_action() function or the automatic
  119. // suggestion theme_fboauth_action__[action_name]().
  120. // 'theme' => 'mymodule_fboauth_action',
  121. );
  122. return $actions;
  123. }
  124. ?>
  125. Then write your function specified as the "callback" in the above hook.
  126. /**
  127. * Facebook OAuth action callback; Import a user's Facebook photos.
  128. */
  129. function mymodule_fboauth_action_photo_import($app_id, $access_token) {
  130. // Query against the Facebook Graph API. See the Facebook API for a list of
  131. // commands: http://developers.facebook.com/docs/reference/api/
  132. $result = fboauth_graph_query('me/photos', $access_token);
  133. foreach ($result['data'] as $photo) {
  134. // Import into Drupal.
  135. }
  136. // Optionally set a completion or error message.
  137. drupal_set_message(t('Import complete!'));
  138. // Optionally return a path to which the user will be redirected. If not set
  139. // the path in the $_REQUEST['destination'] variable will be used. If there
  140. // is no path at all specified, the user will be redirected to the homepage.
  141. return 'mymodule/import-complete';
  142. }
  143. ?>
  144. Now to get the user to actually execute this action, you need to link to
  145. Facebook so that the user can grant the necessary access. You can do this with
  146. the utility function fboauth_action_display(). Our example action was keyed as
  147. "mymodule_photo_import", so we would print the link like this:
  148. Now when the user clicks on the output link, they will have the option of
  149. granting access to the requested information. If they approve, your callback
  150. function will be executed.
  151. More information about Facebook OAuth's other hooks are documented in the
  152. fboauth.api.php file included with this module.
  153. Deauthorization or access revocation from Facebook.
  154. ---------------------------------------------------
  155. If a user revokes access to the application from the Facebook side, and the
  156. application has provided a Deauthorize callback URL (see Install step 2 above),
  157. Facebook will notify your site that the user has disconnected their account from
  158. your site.
  159. A hook is provided to allow other modules to respond to this event as well - see
  160. hook_fboauth_user_deauthorize() in fboauth.api.php file.
  161. Support
  162. -------
  163. Please use the issue queue for filing bugs with this module at
  164. http://drupal.org/project/issues/fboauth?categories=All