You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the autoloader is having trouble detecting the path to the source files, we can define the location of the source code before the `require_once` statement.
Before we can send requests to the Graph API, we need to load our app configuration into the `Facebook\Facebook` service.
93
93
94
-
```
94
+
```php
95
95
$fb = new Facebook\Facebook([
96
96
'app_id' => '{app-id}',
97
97
'app_secret' => '{app-secret}',
@@ -120,7 +120,7 @@ For most websites, you'll use the [`Facebook\Helpers\FacebookRedirectLoginHelper
120
120
> content: "For this example we'll assume `login.php` will present the login link and the user will be redirected to `login-callback.php` where we will obtain the access token.",
121
121
> type: 'info',
122
122
123
-
```
123
+
```php
124
124
# login.php
125
125
$fb = new Facebook\Facebook([/* . . . */]);
126
126
@@ -134,7 +134,7 @@ echo '<a href="' . $loginUrl . '">Log in with Facebook!</a>';
134
134
> content: "The `FacebookRedirectLoginHelper` makes use of sessions to store a [CSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery) value. You need to make sure you have sessions enabled before invoking the `getLoginUrl()` method. This is usually done automatically in most web frameworks, but if you're not using a web framework you can add [`session_start();`](http://php.net/session_start) to the top of your `login.php` & `login-callback.php` scripts.",
135
135
> type: 'warning',
136
136
137
-
```
137
+
```php
138
138
# login-callback.php
139
139
$fb = new Facebook\Facebook([/* . . . */]);
140
140
@@ -168,7 +168,7 @@ If your app is on Facebook Canvas, use the `getAccessToken()` method on [`Facebo
168
168
> content: "The `FacebookCanvasHelper` will detect a [signed request](reference.md#signed-requests) for you and attempt to obtain an access token using the payload data from the signed request. The signed request will only contain the data needed to obtain an access token if the user has already authorized your app sometime in the past. If they have not yet authorized your app the `getAccessToken()` will return `null` and you will need to log the user in with either the [redirect method](#authentication-redirect) or by using the [SDK for JavaScript](https://developers.facebook.com/docs/javascript) and then use the SDK for PHP to [obtain the access token from the cookie](#authentication-javascript) the SDK for JavaScript set.",
169
169
> type: 'warning',
170
170
171
-
```
171
+
```php
172
172
# example-canvas-app.php
173
173
$fb = new Facebook\Facebook([/* . . . */]);
174
174
@@ -198,7 +198,7 @@ if (isset($accessToken)) {
198
198
199
199
If you're already using the Facebook SDK for JavaScript to authenticate users, you can obtain the access token with PHP by using the [FacebookJavaScriptHelper](reference/FacebookJavaScriptHelper.md). The `getAccessToken()` method will return an [`AccessToken`](reference/AccessToken.md) entity.
200
200
201
-
```
201
+
```php
202
202
# example-obtain-from-js-cookie-app.php
203
203
$fb = new Facebook\Facebook([/* . . . */]);
204
204
@@ -229,7 +229,7 @@ When a user first logs into your app, the access token your app receives will be
229
229
230
230
To extend an access token, you can make use of the [`OAuth2Client`](reference/Facebook.md#getoauth2client).
231
231
232
-
```
232
+
```php
233
233
// OAuth 2.0 client handler
234
234
$oAuth2Client = $fb->getOAuth2Client();
235
235
@@ -245,7 +245,7 @@ Once you have an instance of the `Facebook\Facebook` service and obtained an acc
245
245
246
246
In this example we will send a GET request to the Graph API endpoint `/me`. The `/me` endpoint is a special alias to the [user node endpoint](https://developers.facebook.com/docs/graph-api/reference/user) that references the user or Page making the request.
247
247
248
-
```
248
+
```php
249
249
$fb = new Facebook\Facebook([/* . . . */]);
250
250
251
251
// Sets the default fallback access token so we don't have to pass it to each request
@@ -273,7 +273,7 @@ To get the response in the form of a nifty collection, we call `getGraphUser()`
273
273
274
274
If you don't care about fancy collections and just want the response as a plain-old array, you can call the `getDecodedBody()` method on the `FacebookResponse` entity.
0 commit comments