If you don't provide a default_access_token in the configuration options, or you wish to use a different access token than the default, you can explicitly pass the access token as an argument to the get(), post(), and delete() methods.

app_id

The ID of your Facebook app (required).

app_secret

The secret of your Facebook app (required).

default_access_token

The default fallback access token to use if one is not explicitly provided. The value can be of type string or Facebook\AccessToken. If any other value is provided an InvalidArgumentException will be thrown. Defaults to null.

enable_beta_mode

Enable beta mode so that requests are made to the graph.beta.facebook.com endpoint. Set to boolean true to enable or false to disable. Defaults to false.

default_graph_version

Allows you to overwrite the default Graph version number set in Facebook\Facebook::DEFAULT_GRAPH_VERSION. Set this as a string as it would appear in the Graph url, e.g. v2.0. Defaults to the latest version of Graph.

http_client_handler

Allows you to overwrite the default HTTP client.

By default, the SDK will try to use cURL as the HTTP client. If a cURL implementation cannot be found, it will fallback to a stream wrapper HTTP client. You can force either HTTP client implementations by setting this value to curl or stream.

If you wish to use Guzzle, you can set this value to guzzle, but it requires that you install Guzzle with composer.

If you wish to write your own HTTP client, you can code your HTTP client to the [Facebook\HttpClients\FacebookHttpClientInterface](/docs/php/FacebookHttpClientInterface) and set this value to an instance of your custom client.

If any other value is provided an InvalidArgumentException will be thrown.

persistent_data_handler

Allows you to overwrite the default persistent data store.

By default, the SDK will try to use the native PHP session for the persistent data store. There is also an in-memory persistent data handler which is useful when running your script from the command line for example. You can force either implementation by setting this value to session or memory.

If you wish to write your own persistent data handler, you can code your persistent data handler to the [Facebook\PersistentData\PersistentDataInterface](/docs/php/PersistentDataInterface) and set the value of persistent_data_handler to an instance of your custom handler.

If any other value is provided an InvalidArgumentException will be thrown.

url_detection_handler

Allows you to overwrite the default URL detection logic.

The SDK will do its best to detect the proper current URL but this can sometimes get tricky if you have a very customized environment. You can write your own URL detection logic that implements the [Facebook\Url\UrlDetectionInterface](/docs/php/UrlDetectionInterface) and set the value of url_detection_handler to an instance of your custom URL detector.

pseudo_random_string_generator

Generating random strings in PHP is easy but generating cryptographically secure random strings is another matter. By default the SDK will attempt to detect a suitable to cryptographically secure random string generator for you. If a cryptographically secure method cannot be detected, a Facebook\Exceptions\FacebookSDKException will be thrown.

You can force a specific implementation of the CSPRSG's provided in the SDK by setting pseudo_random_string_generator to one of the following methods: mcrypt, openssl and urandom.

You can write your own CSPRSG that implements the [Facebook\PseudoRandomString\PseudoRandomStringGeneratorInterface](/docs/php/PseudoRandomStringGeneratorInterface) and set the value of pseudo_random_string_generator to an instance of your custom generator.

If any other value is provided an InvalidArgumentException will be thrown.

Environment variables fallback

The only required configuration options are app_id and app_secret. However, the SDK will look to environment variables for the app ID and app secret.

To take advantage of this feature, simply set an environment variable named FACEBOOK_APP_ID with your Facebook app ID and set an environment variable named FACEBOOK_APP_SECRET with your Facebook app secret and you will be able to instantiate the Facebook\Facebook service without setting any configuration in the constructor.

$fb = new Facebook\Facebook();

Instance Methods

getApp()

public FacebookApp getApp()

Returns the instance of Facebook\FacebookApp for the instantiated service.

getUrlDetectionHandler()

getDefaultAccessToken()

public Facebook\Authentication\AccessToken|null getDefaultAccessToken()

Returns the default fallback AccessToken entity that is being used with every request to Graph. This value can be set with the configuration option default_access_token or by using setDefaultAccessToken().

setDefaultAccessToken()

public setDefaultAccessToken(string|Facebook\AccessToken $accessToken)

Sets the default fallback access token to be use with all requests sent to Graph. The access token must be a string.

$endpoint
The url to send to Graph without the version prefix (required).

$fb->get('/me');

$accessToken
The access token (as a string or AccessToken entity) to use for the request. If none is provided, the SDK will assume the value from the default_access_token configuration option if it was set.

$eTagGraph supports eTags. Set this to the eTag from a previous request to get a 304 Not Modified response if the data has not changed.

$graphVersion
This will overwrite the Graph version that was set in the default_graph_version configuration option.

request()

Instantiates a new Facebook\FacebookRequest entity but does not send the request to Graph. This is useful for creating a number of requests to be sent later in a batch request (see sendBatchRequest() below).

The arguments are the same as post() above with the exception of $method.

$method
The HTTP request verb to use for this request. This can be set to any verb that the $graphVersion of Graph supports, e.g. GET, POST, DELETE, etc.

getPageTabHelper()

public Facebook\Helpers\FacebookPageTabHelper getPageTabHelper()

Returns a Facebook\Helpers\FacebookPageTabHelper which is used to access the signed request that is POSTed to canvas apps and provides a number of helper methods useful for apps living in a page tab context.

videoToUpload()

Uploading videos to Graph requires that you send the request to https://graph-video.facebook.com instead of the normal https://graph.facebook.com host name. When you use videoToUpload() to upload a video, the SDK for PHP will automatically point the request to the graph-video.facebook.com host name for you.