Campustream 1.0
A social network MQP for WPI
Facebook Class Reference

Public Member Functions

 __construct ($config)
 setAppId ($appId)
 getAppId ()
 setApiSecret ($apiSecret)
 getApiSecret ()
 setCookieSupport ($cookieSupport)
 useCookieSupport ()
 setBaseDomain ($domain)
 getBaseDomain ()
 setFileUploadSupport ($fileUploadSupport)
 useFileUploadSupport ()
 getSignedRequest ()
 setSession ($session=null, $write_cookie=true)
 getSession ()
 getUser ()
 getAccessToken ()
 getLoginUrl ($params=array())
 getLogoutUrl ($params=array())
 getLoginStatusUrl ($params=array())
 api ()

Data Fields

const VERSION = '2.1.2'

Static Public Attributes

static $CURL_OPTS
static $DOMAIN_MAP

Protected Member Functions

 _restserver ($params)
 _graph ($path, $method='GET', $params=array())
 _oauthRequest ($url, $params)
 makeRequest ($url, $params, $ch=null)
 getSessionCookieName ()
 setCookieFromSession ($session=null)
 validateSessionObject ($session)
 createSessionFromSignedRequest ($data)
 parseSignedRequest ($signed_request)
 getApiUrl ($method)
 getUrl ($name, $path='', $params=array())
 getCurrentUrl ()

Static Protected Member Functions

static generateSignature ($params, $secret)
static errorLog ($msg)
static base64UrlDecode ($input)

Protected Attributes

 $appId
 $apiSecret
 $session
 $signedRequest
 $sessionLoaded = false
 $cookieSupport = false
 $baseDomain = ''
 $fileUploadSupport = false

Static Protected Attributes

static $DROP_QUERY_PARAMS

Detailed Description

Provides access to the Facebook Platform.

Author:
Naitik Shah <naitik@facebook.com>

Definition at line 98 of file facebook.php.


Constructor & Destructor Documentation

__construct ( config)

Initialize a Facebook Application.

The configuration:

  • appId: the application ID
  • secret: the application secret
  • cookie: (optional) boolean true to enable cookie support
  • domain: (optional) domain for the cookie
  • fileUpload: (optional) boolean indicating if file uploads are enabled
Parameters:
Array$configthe application configuration

Definition at line 186 of file facebook.php.


Member Function Documentation

_graph ( path,
method = 'GET',
params = array() 
) [protected]

Invoke the Graph API.

Parameters:
String$paththe path (required)
String$methodthe http method (default 'GET')
Array$paramsthe query/post data
Returns:
the decoded response object
Exceptions:
FacebookApiException

Definition at line 529 of file facebook.php.

_oauthRequest ( url,
params 
) [protected]

Make a OAuth Request

Parameters:
String$paththe path (required)
Array$paramsthe query/post data
Returns:
the decoded response object
Exceptions:
FacebookApiException

Definition at line 564 of file facebook.php.

_restserver ( params) [protected]

Invoke the old restserver.php endpoint.

Parameters:
Array$paramsmethod call object
Returns:
the decoded response object
Exceptions:
FacebookApiException

Definition at line 503 of file facebook.php.

api ( )

Make an API call.

Parameters:
Array$paramsthe API call parameters
Returns:
the decoded response

Definition at line 487 of file facebook.php.

static base64UrlDecode ( input) [static, protected]

Base64 encoding that doesn't need to be urlencode()ed. Exactly the same as base64_encode except it uses

  • instead of + _ instead of /
Parameters:
Stringbase64UrlEncodeded string

Definition at line 960 of file facebook.php.

createSessionFromSignedRequest ( data) [protected]

Returns something that looks like our JS session object from the signed token's data

TODO: Nuke this once the login flow uses OAuth2

Parameters:
Arraythe output of getSignedRequest
Returns:
Array Something that will work as a session

Definition at line 729 of file facebook.php.

static errorLog ( msg) [static, protected]

Prints to the error log if you aren't in command line mode.

Parameters:
Stringlog message

Definition at line 941 of file facebook.php.

static generateSignature ( params,
secret 
) [static, protected]

Generate a signature for the given params and secret.

Parameters:
Array$paramsthe parameters to sign
String$secretthe secret to sign with
Returns:
String the generated signature

Definition at line 922 of file facebook.php.

getAccessToken ( )

Gets a OAuth access token.

Returns:
String the access token

Definition at line 394 of file facebook.php.

getApiSecret ( )

Get the API Secret.

Returns:
String the API Secret

Definition at line 234 of file facebook.php.

getApiUrl ( method) [protected]

Build the URL for api given parameters.

Parameters:
$methodString the method name.
Returns:
String the URL for the given parameters

Definition at line 787 of file facebook.php.

getAppId ( )

Get the Application ID.

Returns:
String the Application ID

Definition at line 215 of file facebook.php.

getBaseDomain ( )

Get the base domain for the Cookie.

Returns:
String the base domain

Definition at line 272 of file facebook.php.

getCurrentUrl ( ) [protected]

Returns the Current URL, stripping it of known FB parameters that should not persist.

Returns:
String the current URL

Definition at line 884 of file facebook.php.

getLoginStatusUrl ( params = array())

Get a login status URL to fetch the status from facebook.

The parameters:

  • ok_session: the URL to go to if a session is found
  • no_session: the URL to go to if the user is not connected
  • no_user: the URL to go to if the user is not signed into facebook
Parameters:
Array$paramsprovide custom parameters
Returns:
String the URL for the logout flow

Definition at line 467 of file facebook.php.

getLoginUrl ( params = array())

Get a Login URL for use with redirects. By default, full page redirect is assumed. If you are using the generated URL with a window.open() call in JavaScript, you can pass in display=popup as part of the $params.

The parameters:

  • next: the url to go to after a successful login
  • cancel_url: the url to go to after the user cancels
  • req_perms: comma separated list of requested extended perms
  • display: can be "page" (default, full page) or "popup"
Parameters:
Array$paramsprovide custom parameters
Returns:
String the URL for the login flow

Definition at line 418 of file facebook.php.

getLogoutUrl ( params = array())

Get a Logout URL suitable for use with redirects.

The parameters:

  • next: the url to go to after a successful logout
Parameters:
Array$paramsprovide custom parameters
Returns:
String the URL for the logout flow

Definition at line 445 of file facebook.php.

getSession ( )

Get the session object. This will automatically look for a signed session sent via the signed_request, Cookie or Query Parameters if needed.

Returns:
Array the session

Definition at line 333 of file facebook.php.

getSessionCookieName ( ) [protected]

The name of the Cookie that contains the session.

Returns:
String the cookie name

Definition at line 641 of file facebook.php.

getSignedRequest ( )

Get the data from a signed_request token

Returns:
String the base domain

Definition at line 300 of file facebook.php.

getUrl ( name,
path = '',
params = array() 
) [protected]

Build the URL for given domain alias, path and parameters.

Parameters:
$nameString the name of the domain
$pathString optional path (without a leading slash)
$paramsArray optional query parameters
Returns:
String the URL for the given parameters

Definition at line 864 of file facebook.php.

getUser ( )

Get the UID from the session.

Returns:
String the UID if available

Definition at line 384 of file facebook.php.

makeRequest ( url,
params,
ch = null 
) [protected]

Makes an HTTP request. This method can be overriden by subclasses if developers want to do fancier things or use something other than curl to make the request.

Parameters:
String$urlthe URL to make the request to
Array$paramsthe parameters to use for the POST body
CurlHandler$choptional initialized curl handle
Returns:
String the response text

Definition at line 588 of file facebook.php.

parseSignedRequest ( signed_request) [protected]

Parses a signed_request and validates the signature. Then saves it in $this->signed_data

Parameters:
StringA signed token
BooleanShould we remove the parts of the payload that are used by the algorithm?
Returns:
Array the payload inside it or null if the sig is wrong

Definition at line 758 of file facebook.php.

setApiSecret ( apiSecret)

Set the API Secret.

Parameters:
String$appIdthe API Secret

Definition at line 224 of file facebook.php.

setAppId ( appId)

Set the Application ID.

Parameters:
String$appIdthe Application ID

Definition at line 205 of file facebook.php.

setBaseDomain ( domain)

Set the base domain for the Cookie.

Parameters:
String$domainthe base domain

Definition at line 262 of file facebook.php.

setCookieFromSession ( session = null) [protected]

Set a JS Cookie based on the _passed in_ session. It does not use the currently stored session -- you need to explicitly pass it in.

Parameters:
Array$sessionthe session to use for setting the cookie

Definition at line 651 of file facebook.php.

setCookieSupport ( cookieSupport)

Set the Cookie Support status.

Parameters:
Boolean$cookieSupportthe Cookie Support status

Definition at line 243 of file facebook.php.

setFileUploadSupport ( fileUploadSupport)

Set the file upload support status.

Parameters:
String$domainthe base domain

Definition at line 281 of file facebook.php.

setSession ( session = null,
write_cookie = true 
)

Set the Session.

Parameters:
Array$sessionthe session
Boolean$write_cookieindicate if a cookie should be written. this value is ignored if cookie support has been disabled.

Definition at line 317 of file facebook.php.

useCookieSupport ( )

Get the Cookie Support status.

Returns:
Boolean the Cookie Support status

Definition at line 253 of file facebook.php.

useFileUploadSupport ( )

Get the file upload support status.

Returns:
String the base domain

Definition at line 291 of file facebook.php.

validateSessionObject ( session) [protected]

Validates a session_version=3 style session object.

Parameters:
Array$sessionthe session object
Returns:
Array the session object if it validates, null otherwise

Definition at line 696 of file facebook.php.


Field Documentation

$apiSecret [protected]

The Application API Secret.

Definition at line 142 of file facebook.php.

$appId [protected]

The Application ID.

Definition at line 137 of file facebook.php.

$baseDomain = '' [protected]

Base domain for the Cookie.

Definition at line 167 of file facebook.php.

$cookieSupport = false [protected]

Indicates if Cookie support should be enabled.

Definition at line 162 of file facebook.php.

$CURL_OPTS [static]
Initial value:
 array(
    CURLOPT_CONNECTTIMEOUT => 10,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT        => 60,
    CURLOPT_USERAGENT      => 'facebook-php-2.0',
  )

Default options for curl.

Definition at line 108 of file facebook.php.

$DOMAIN_MAP [static]
Initial value:
 array(
    'api'      => 'https://api.facebook.com/',
    'api_read' => 'https://api-read.facebook.com/',
    'graph'    => 'https://graph.facebook.com/',
    'www'      => 'https://www.facebook.com/',
  )

Maps aliases to Facebook domains.

Definition at line 127 of file facebook.php.

$DROP_QUERY_PARAMS [static, protected]
Initial value:
 array(
    'session',
    'signed_request',
  )

List of query parameters that get automatically dropped when rebuilding the current URL.

Definition at line 119 of file facebook.php.

$fileUploadSupport = false [protected]

Indicates if the CURL based @ syntax for file uploads is enabled.

Definition at line 172 of file facebook.php.

$session [protected]

The active user session, if one is available.

Definition at line 147 of file facebook.php.

$sessionLoaded = false [protected]

Indicates that we already loaded the session as best as we could.

Definition at line 157 of file facebook.php.

$signedRequest [protected]

The data from the signed_request token.

Definition at line 152 of file facebook.php.

const VERSION = '2.1.2'

Version.

Definition at line 103 of file facebook.php.


The documentation for this class was generated from the following file: