Skip to content

Commit

Permalink
API update to Facebook PHP SDK v4
Browse files Browse the repository at this point in the history
  • Loading branch information
wilr committed Jun 29, 2014
1 parent 66b7a6e commit 26602ae
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 235 deletions.
39 changes: 23 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ interface. If you want to use the OAuth version see

### What it provides

* Loads and setups Facebook Connect for Single Sign on via the Javascript SDK
* Loads and setups Facebook Connect for Single Sign on via the Javascript SDK or
via a basic HTTP redirect

* Authenticates users visiting the site - if they are logged into Facebook then
you can access their information via the following controls. You can also
Expand Down Expand Up @@ -48,13 +49,13 @@ it won't save the information to the database
To setup Facebook Connect your first need to download the module:

```
composer require wilr/silverstripe-facebookconnect
composer require "wilr/silverstripe-facebookconnect" "dev-master"
```

[Register your website / application](https://developers.facebook.com/apps/?action=create)
with Facebook.

Set your configuration through the SilverStripe Config API. For instance, you
Set your configuration through the SilverStripe config API. For instance, you
could put this in your `mysite/_config/facebookconnect.yml` file:

```
Expand All @@ -66,6 +67,11 @@ FacebookControllerExtension:
Update the database by running `/dev/build` to add the additional fields to
the `Member` table.

To allow the user to login to the application either do it via the javascript
SDK or use the simple HTTP requests.

#### Javascript SDK

Include the `ConnectInit.ss` template in the `<body>` part of every site you
wish to call a Facebook function. This includes the Facebook JavaScript SDK.

Expand All @@ -74,32 +80,33 @@ E.g. on `Page.ss`
```
<body>
<% include ConnectInit %>
...
```

Once you have done that you should be able to use the includes provided in this
module.
#### Standard Method

```
<% if CurrentFacebookMember %>
<p>Hi $CurrentFacebookMember.FirstName</p>
<% include ConnectLogout %>
<% else %>
<% include ConnectLogin %>
<% end_if %>
<a href="$FacebookLoginLink">Login via Facebook</a>
```

You can also access the Facebook member information in your PHP code. The
Facebook API connection and current member are cached on the controller object.
So for example if this is in your Page_Controller class
You can also access the Facebook member information in your PHP code..

```php
// returns the current facebook member (wrapped in a SS Member Object)
$this->getCurrentFacebookMember();

// returns the API connection which you can use to write your own query
$this->getFacebook();
// while in a controller
$this->getFacebookSession();

// if you're not in a controller
Controller::curr()->getFacebookSession();

```

For more information about what you can do through the SDK see
https://developers.facebook.com/docs/reference/php/4.0.0

### Options

All the following values are set either via the PHP Config API like follows
Expand Down Expand Up @@ -136,7 +143,7 @@ A list of group codes to add the user. For instance if you want every member who
joins through facebook to be added to a group `Facebook Members` set the
following:

FacebookConnectExtensions:
FacebookControllerExtension:
member_groups:
- facebook_members

Expand Down
2 changes: 1 addition & 1 deletion _config/facebookconnect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Member:

Controller:
extensions:
- FacebookConnectExtension
- FacebookControllerExtension

Authenticator::
authenticators:
Expand Down
6 changes: 3 additions & 3 deletions code/FacebookAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function authenticate($RAW_data, Form $form = null) {
}

/**
* Return the facebook login form
* Return the Facebook login form
*
* @return Form
*/
Expand All @@ -29,9 +29,9 @@ public static function get_login_form(Controller $controller) {
}

/**
* Return the name for the facebook tab
* Return the name for the Facebook tab
*
* @return String
* @return string
*/
public static function get_name() {
return _t('FacebookAuthenicator.TITLE', "Facebook Connect");
Expand Down
Loading

0 comments on commit 26602ae

Please sign in to comment.