You are here

README.txt in Facebook OAuth (FBOAuth) 7.2

Same filename and directory in other branches
  1. 6 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 7.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". Be sure to set the contact e-mail addresses for the app and
   enable the app for use by the public. You may need to request review of
   your application with Facebook if you are requesting access to certain data.
   In order to get reviewed, you will need to provide Facebok with various
   pieces of information including a privacy policy, a description of your application,
   and notes for why you want to request information about the various fields
   that you request from Facebook.

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 on the Modules page.

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

   Set the API version of the Facebook App.

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