Facebook Developers
DocsToolsSupportNewsApps
Log In
  • Social Plugins
  • Facebook Login
  • Open Graph
  • Facebook APIs
  • Games
  • Media
  • Payments
  • App Center
  • Promote Your App
  • iOS
  • Android
  • Web
    • Getting Started
    • JavaScript SDK
    • PHP SDK
    • More SDKs
    • Facebook for WordPress
  • Technology Partners
  • Facebook Object
    • api
    • getAccessToken
    • getApiSecret
    • getAppId
    • getLoginStatusUrl
    • getLoginUrl
    • getLogoutUrl
    • getSignedRequest
    • getUser
    • setAccessToken
    • setApiSecret
    • setAppId
    • setFileUploadSupport
    • useFileUploadSupport
  • FacebookApiException
    • getResult
    • getType

PHP SDK Reference

Web › PHP SDK Reference

The Facebook SDK for PHP provides a rich set of server-side functionality for accessing Facebook's server-side API calls such as the Graph API and FQL. It also works alongside the Facebook SDK for Javascript to help you implement Facebook Login.

Take a look at the Getting Started guide for full information about features and usage.

Installing and Initializing

To install the SDK, first download the source from GitHub.

Next, extract the package and copy the files from the src/ directory to a directory on the server where you will host your app, for example php-sdk. Then, just include php-sdk/facebook.php wherever you want to use the SDK. You use the SDK by instantiating a new Facebook object with, at a minimum, your app id and app secret:

require_once("facebook.php");

$config = array();
$config['appId'] = 'YOUR_APP_ID';
$config['secret'] = 'YOUR_APP_SECRET';

$facebook = new Facebook($config);

For more information see the Getting Started guide.

Classes

  • Facebook Object
  • FacebookApiException

Facebook Object

api

Call a Graph API method or an FQL Query using the PHP SDK.

getAccessToken

Get the current access token being used by the SDK.

getApiSecret

Get the App secret that the SDK is currently using.

getAppId

Get the App ID that the SDK is currently using.

getLoginStatusUrl

Returns a URL based on the user’s login status on Facebook.

getLoginUrl

Get a URL that the user can click to login, authorize the app, and get redirected back to the app.

getLogoutUrl

This method returns a URL that, when clicked by the user, will log them out of their Facebook session and then redirect them back to your application.

getSignedRequest

Get the current signed request being used by the SDK.

getUser

This method returns the Facebook User ID of the current user, or 0 if there is no logged-in user.

setAccessToken

Set the current access token being used by the SDK.

setApiSecret

Set the App secret that the SDK is currently using.

setAppId

Set the App ID that the SDK is currently using.

setFileUploadSupport

Set file upload support in the SDK.

useFileUploadSupport

Get whether file upload support has been enabled in the SDK.


FacebookApiException

getResult

Get the object that is the result of the error or exception returned by the server.

getType

Get the type for the error or exception, e.g. OAuthException.

Updated last Friday
Facebook © 2013 · English (US)
AboutAdvertisingCareersPlatform PoliciesPrivacy Policy