Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Starting with version 5, the Facebook PHP SDK follows [SemVer](http://semver.org
- Replace custom CSPRNG implementation with `paragonie/random_compat` (#644)
- Removed the built-in autoloader in favor of composer's autoloader (#646)
- Big integers in signed requests get decoded as `string` instead of `float` (#699)
- Remove helpers

## 5.x

Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ $fb = new \Facebook\Facebook([
//'default_access_token' => '{access-token}', // optional
]);

// Use one of the helper classes to get a Facebook\Authentication\AccessToken entity.
// $helper = $fb->getRedirectLoginHelper();
// $helper = $fb->getJavaScriptHelper();
// $helper = $fb->getCanvasHelper();
// $helper = $fb->getPageTabHelper();

try {
// Get the \Facebook\GraphNodes\GraphUser object for the current user.
// If you provided a 'default_access_token', the '{access-token}' is optional.
Expand Down
1 change: 0 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ For installation & implementation instructions, look through the [Getting Starte
The following examples demonstrate how you would accomplish common tasks with the Facebook SDK for PHP.

- **Authentication & Signed Requests**
- [Facebook Login (OAuth 2.0)](./examples/facebook_login.md)
- [Obtaining an access token from the SDK for JavaScript](./examples/access_token_from_javascript.md)
- [Obtaining an access token within a Facebook Canvas context](./examples/access_token_from_canvas.md)
- [Obtaining an access token within a Facebook Page tab context](./examples/access_token_from_page_tab.md)
Expand Down
33 changes: 14 additions & 19 deletions docs/examples/access_token_from_canvas.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,32 @@ This example covers obtaining an access token and signed request from within the

## Example

A signed request will be sent to your app via the HTTP POST method within the context of app canvas. The PHP SDK provides a helper to easily obtain, validate & decode the signed request. If the proper OAuth data exists in the signed request payload data, an attempt can be made to obtain an access token from the Graph API.
A signed request will be sent to your app via the HTTP POST method within the context of app canvas. The PHP SDK provides a helper to validate & decode the signed request.

```php
$fb = new Facebook\Facebook([
'app_id' => '{app-id}',
'app_secret' => '{app-secret}',
'default_graph_version' => 'v2.9',
]);

$helper = $fb->getCanvasHelper();
'app_id' => '{app-id}',
'app_secret' => '{app-secret}',
'default_graph_version' => 'v2.9',
]);

try {
$accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
$signedRequest = new SignedRequest($fb->getApp(), $_POST['signed_request'])
$accessToken = $signedRequest->getAccessToken();
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}

if (! isset($accessToken)) {
echo 'No OAuth data could be obtained from the signed request. User has not authorized your app yet.';
exit;
if (!isset($accessToken)) {
echo 'No OAuth data could be obtained from the signed request. User has not authorized your app yet.';
exit;
}

// Logged in
echo '<h3>Signed Request</h3>';
var_dump($helper->getSignedRequest());
var_dump($signedRequest->getPayload());

echo '<h3>Access Token</h3>';
var_dump($accessToken->getValue());
Expand Down
30 changes: 13 additions & 17 deletions docs/examples/access_token_from_javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,24 @@ After the user successfully logs in, redirect the user (or make an AJAX request)
```php
# /js-login.php
$fb = new Facebook\Facebook([
'app_id' => '{app-id}',
'app_secret' => '{app-secret}',
'default_graph_version' => 'v2.9',
]);

$helper = $fb->getJavaScriptHelper();
'app_id' => '{app-id}',
'app_secret' => '{app-secret}',
'default_graph_version' => 'v2.9',
]);

try {
$accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
$fbApp = $fb->getApp();
$signedRequest = new SignedRequest($fbApp, $_COOKIE['fbsr_' . $fbApp->getId()]))
$accessToken = $signedRequest->getAccessToken();
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}

if (! isset($accessToken)) {
echo 'No cookie set or no OAuth data could be obtained from cookie.';
exit;
if (!isset($accessToken)) {
echo 'No cookie set or no OAuth data could be obtained from cookie.';
exit;
}

// Logged in
Expand Down
36 changes: 16 additions & 20 deletions docs/examples/access_token_from_page_tab.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- @TODO: Rewrite doc -->
# Get Access Token From Page Tab Example

This example covers obtaining an access token and signed request from within the context of a page tab with the Facebook SDK for PHP.
Expand All @@ -8,39 +9,34 @@ Page tabs behave much like the app canvas. The PHP SDK provides a helper for pag

```php
$fb = new Facebook\Facebook([
'app_id' => '{app-id}',
'app_secret' => '{app-secret}',
'default_graph_version' => 'v2.9',
]);

$helper = $fb->getPageTabHelper();
'app_id' => '{app-id}',
'app_secret' => '{app-secret}',
'default_graph_version' => 'v2.9',
]);

try {
$accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
$signedRequest = new SignedRequest($fb->getApp(), $_POST['signed_request'])
$accessToken = $signedRequest->getAccessToken();
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}

if (! isset($accessToken)) {
echo 'No OAuth data could be obtained from the signed request. User has not authorized your app yet.';
exit;
if (!isset($accessToken)) {
echo 'No OAuth data could be obtained from the signed request. User has not authorized your app yet.';
exit;
}

// Logged in
echo '<h3>Page ID</h3>';
var_dump($helper->getPageId());
var_dump($signedRequest->get('page')['id']);

echo '<h3>User is admin of page</h3>';
var_dump($helper->isAdmin());
var_dump($signedRequest->get('page')['admin'] === true);

echo '<h3>Signed Request</h3>';
var_dump($helper->getSignedRequest());
var_dump($signedRequest->getPayload());

echo '<h3>Access Token</h3>';
var_dump($accessToken->getValue());
Expand Down
101 changes: 0 additions & 101 deletions docs/examples/facebook_login.md

This file was deleted.

Loading