Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes

BaseFacebook Class Reference

Inheritance diagram for BaseFacebook:
Collaboration diagram for BaseFacebook:

List of all members.

Public Member Functions

 __construct ($config)
 setAppId ($appId)
 getAppId ()
 setApiSecret ($apiSecret)
 getApiSecret ()
 setFileUploadSupport ($fileUploadSupport)
 useFileUploadSupport ()
 setAccessToken ($access_token)
 getAccessToken ()
 getSignedRequest ()
 getUser ()
 getLoginUrl ($params=array())
 getLogoutUrl ($params=array())
 getLoginStatusUrl ($params=array())
 api ()
 destroySession ()

Public Attributes

const VERSION = '3.1.1'

Static Public Attributes

static $CURL_OPTS
static $DOMAIN_MAP

Protected Member Functions

 getUserAccessToken ()
 getUserFromAvailableData ()
 getSignedRequestCookieName ()
 getCode ()
 getUserFromAccessToken ()
 getApplicationAccessToken ()
 establishCSRFTokenState ()
 getAccessTokenFromCode ($code, $redirect_uri=null)
 _restserver ($params)
 _graph ($path, $method= 'GET', $params=array())
 _oauthRequest ($url, $params)
 makeRequest ($url, $params, $ch=null)
 parseSignedRequest ($signed_request)
 getApiUrl ($method)
 getUrl ($name, $path='', $params=array())
 getCurrentUrl ()
 shouldRetainParam ($param)
 throwAPIException ($result)
 setPersistentData ($key, $value)
 getPersistentData ($key, $default=false)
 clearPersistentData ($key)
 clearAllPersistentData ()

Static Protected Member Functions

static errorLog ($msg)
static base64UrlDecode ($input)

Protected Attributes

 $appId
 $apiSecret
 $user
 $signedRequest
 $state
 $accessToken = null
 $fileUploadSupport = false

Static Protected Attributes

static $DROP_QUERY_PARAMS

Detailed Description

Provides access to the Facebook Platform. This class provides a majority of the functionality needed, but the class is abstract because it is designed to be sub-classed. The subclass must implement the four abstract methods listed at the bottom of the file.

Author:
Naitik Shah <[email protected]>

Definition at line 118 of file base_facebook.php.


Constructor & Destructor Documentation

BaseFacebook.__construct ( config  ) 

Initialize a Facebook Application.

The configuration:

  • appId: the application ID
  • secret: the application secret
  • fileUpload: (optional) boolean indicating if file uploads are enabled
Parameters:
array $config The application configuration

Reimplemented in Facebook.

Definition at line 212 of file base_facebook.php.


Member Function Documentation

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

Invoke the Graph API.

Parameters:
string $path The path (required)
string $method The http method (default 'GET')
array $params The query/post data
Returns:
mixed The decoded response object
Exceptions:
FacebookApiException 

Definition at line 730 of file base_facebook.php.

BaseFacebook._oauthRequest ( url,
params 
) [protected]

Make a OAuth Request.

Parameters:
string $url The path (required)
array $params The query/post data
Returns:
string The decoded response object
Exceptions:
FacebookApiException 

Definition at line 759 of file base_facebook.php.

BaseFacebook._restserver ( params  )  [protected]

Invoke the old restserver.php endpoint.

Parameters:
array $params Method call object
Returns:
mixed The decoded response object
Exceptions:
FacebookApiException 

Definition at line 697 of file base_facebook.php.

BaseFacebook.api (  ) 

Make an API call.

Returns:
mixed The decoded response

Definition at line 548 of file base_facebook.php.

static BaseFacebook.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:
string $input base64UrlEncoded string
Returns:
string

Definition at line 1085 of file base_facebook.php.

BaseFacebook.clearAllPersistentData (  )  [abstract, protected]

Clear all data from the persistent storage

Returns:
void

Reimplemented in Facebook.

BaseFacebook.clearPersistentData ( key  )  [abstract, protected]

Clear the data with $key from the persistent storage

Parameters:
string $key
Returns:
void

Reimplemented in Facebook.

BaseFacebook.destroySession (  ) 

Destroy the current session

Definition at line 1092 of file base_facebook.php.

static BaseFacebook.errorLog ( msg  )  [static, protected]

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

Parameters:
string $msg Log message

Definition at line 1065 of file base_facebook.php.

BaseFacebook.establishCSRFTokenState (  )  [protected]

Lays down a CSRF state token for this process.

Returns:
void

Definition at line 632 of file base_facebook.php.

BaseFacebook.getAccessToken (  ) 

Determines the access token that should be used for API calls. The first time this is called, $this->accessToken is set equal to either a valid user access token, or it's set to the application access token if a valid user access token wasn't available. Subsequent calls return whatever the first call returned.

Returns:
string The access token

Definition at line 307 of file base_facebook.php.

BaseFacebook.getAccessTokenFromCode ( code,
redirect_uri = null 
) [protected]

Retrieves an access token for the given authorization code (previously generated from www.facebook.com on behalf of a specific user). The authorization code is sent to graph.facebook.com and a legitimate access token is generated provided the access token and the user for which it was generated all match, and the user is either logged in to Facebook or has granted an offline access permission.

Parameters:
string $code An authorization code.
Returns:
mixed An access token exchanged for the authorization code, or false if an access token could not be generated.

Definition at line 651 of file base_facebook.php.

BaseFacebook.getApiSecret (  ) 

Get the API Secret.

Returns:
string the API Secret

Definition at line 261 of file base_facebook.php.

BaseFacebook.getApiUrl ( method  )  [protected]

Build the URL for api given parameters.

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

Definition at line 869 of file base_facebook.php.

BaseFacebook.getAppId (  ) 

Get the Application ID.

Returns:
string the Application ID

Definition at line 241 of file base_facebook.php.

BaseFacebook.getApplicationAccessToken (  )  [protected]

Returns the access token that should be used for logged out users when no authorization code is available.

Returns:
string The application access token, useful for gathering public information about users and applications.

Definition at line 623 of file base_facebook.php.

BaseFacebook.getCode (  )  [protected]

Get the authorization code from the query parameters, if it exists, and otherwise return false to signal no authorization code was discoverable.

Returns:
mixed The authorization code, or false if the authorization code could not be determined.

Definition at line 578 of file base_facebook.php.

BaseFacebook.getCurrentUrl (  )  [protected]

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

Returns:
string The current URL

Definition at line 970 of file base_facebook.php.

BaseFacebook.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 $params Provide custom parameters
Returns:
string The URL for the logout flow

Definition at line 529 of file base_facebook.php.

BaseFacebook.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:

  • redirect_uri: the url to go to after a successful login
  • scope: comma separated list of requested extended perms
Parameters:
array $params Provide custom parameters
Returns:
string The URL for the login flow

Definition at line 478 of file base_facebook.php.

BaseFacebook.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 $params Provide custom parameters
Returns:
string The URL for the logout flow

Definition at line 507 of file base_facebook.php.

BaseFacebook.getPersistentData ( key,
default = false 
) [abstract, protected]

Get the data for $key, persisted by BaseFacebook.setPersistentData()

Parameters:
string $key The key of the data to retrieve
boolean $default The default value to return if $key is not found
Returns:
mixed

Reimplemented in Facebook.

BaseFacebook.getSignedRequest (  ) 

Retrieve the signed request, either from a request parameter or, if not present, from a cookie.

Returns:
string the signed request, if available, or null otherwise.

Definition at line 393 of file base_facebook.php.

BaseFacebook.getSignedRequestCookieName (  )  [protected]

Constructs and returns the name of the cookie that potentially houses the signed request for the app user. The cookie is not set by the BaseFacebook class, but it may be set by the JavaScript SDK.

Returns:
string the name of the cookie that would house the signed request value.

Definition at line 566 of file base_facebook.php.

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

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

Parameters:
$name string The name of the domain
$path string Optional path (without a leading slash)
$params array Optional query parameters
Returns:
string The URL for the given parameters

Definition at line 949 of file base_facebook.php.

BaseFacebook.getUser (  ) 

Get the UID of the connected user, or 0 if the Facebook user is not connected.

Returns:
string the UID if available.

Definition at line 412 of file base_facebook.php.

BaseFacebook.getUserAccessToken (  )  [protected]

Determines and returns the user access token, first using the signed request if present, and then falling back on the authorization code if present. The intent is to return a valid user access token, or false if one is determined to not be available.

Returns:
string A valid user access token, or false if one could not be determined.

Definition at line 335 of file base_facebook.php.

BaseFacebook.getUserFromAccessToken (  )  [protected]

Retrieves the UID with the understanding that $this->accessToken has already been set and is seemingly legitimate. It relies on Facebook's Graph API to retrieve user information and then extract the user ID.

Returns:
integer Returns the UID of the Facebook user, or 0 if the Facebook user could not be determined.

Definition at line 607 of file base_facebook.php.

BaseFacebook.getUserFromAvailableData (  )  [protected]

Determines the connected user by first examining any signed requests, then considering an authorization code, and then falling back to any persistent store storing the user.

Returns:
integer The id of the connected Facebook user, or 0 if no such user exists.

Definition at line 429 of file base_facebook.php.

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

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

Parameters:
string $url The URL to make the request to
array $params The parameters to use for the POST body
CurlHandler $ch Initialized curl handle
Returns:
string The response text

Definition at line 785 of file base_facebook.php.

BaseFacebook.parseSignedRequest ( signed_request  )  [protected]

Parses a signed_request and validates the signature.

Parameters:
string $signed_request A signed token
Returns:
array The payload inside it or null if the sig is wrong

Definition at line 840 of file base_facebook.php.

BaseFacebook.setAccessToken ( access_token  ) 

Sets the access token for api calls. Use this if you get your access token by other means and just want the SDK to use it.

Parameters:
string $access_token an access token.
Returns:
BaseFacebook

Definition at line 293 of file base_facebook.php.

BaseFacebook.setApiSecret ( apiSecret  ) 

Set the API Secret.

Parameters:
string $apiSecret The API Secret
Returns:
BaseFacebook

Definition at line 251 of file base_facebook.php.

BaseFacebook.setAppId ( appId  ) 

Set the Application ID.

Parameters:
string $appId The Application ID
Returns:
BaseFacebook

Definition at line 231 of file base_facebook.php.

BaseFacebook.setFileUploadSupport ( fileUploadSupport  ) 

Set the file upload support status.

Parameters:
boolean $fileUploadSupport The file upload support status.
Returns:
BaseFacebook

Definition at line 271 of file base_facebook.php.

BaseFacebook.setPersistentData ( key,
value 
) [abstract, protected]

Each of the following four methods should be overridden in a concrete subclass, as they are in the provided Facebook class. The Facebook class uses PHP sessions to provide a primitive persistent store, but another subclass--one that you implement-- might use a database, memcache, or an in-memory cache.

See also:
Facebook Stores the given ($key, $value) pair, so that future calls to getPersistentData($key) return $value. This call may be in another request.
Parameters:
string $key
array $value
Returns:
void

Reimplemented in Facebook.

BaseFacebook.shouldRetainParam ( param  )  [protected]

Returns true if and only if the key or key/value pair should be retained as part of the query string. This amounts to a brute-force search of the very small list of Facebook-specific params that should be stripped out.

Parameters:
string $param A key or key/value pair within a URL's query (e.g. 'foo=a', 'foo=', or 'foo'.
Returns:
boolean

Definition at line 1020 of file base_facebook.php.

BaseFacebook.throwAPIException ( result  )  [protected]

Analyzes the supplied result to see if it was thrown because the access token is no longer valid. If that is the case, then the persistent store is cleared.

Parameters:
$result array A record storing the error message returned by a failed API call.

Definition at line 1038 of file base_facebook.php.

BaseFacebook.useFileUploadSupport (  ) 

Get the file upload support status.

Returns:
boolean true if and only if the server supports file upload.

Definition at line 281 of file base_facebook.php.


Member Data Documentation

BaseFacebook.$accessToken = null [protected]

Definition at line 193 of file base_facebook.php.

BaseFacebook.$apiSecret [protected]

Definition at line 168 of file base_facebook.php.

BaseFacebook.$appId [protected]

Definition at line 161 of file base_facebook.php.

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

Default options for curl.

Definition at line 128 of file base_facebook.php.

BaseFacebook.$DOMAIN_MAP [static]
Initial value:
 array(
    'api'       => 'https://api.facebook.com/',
    'api_video' => 'https://api-video.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 148 of file base_facebook.php.

BaseFacebook.$DROP_QUERY_PARAMS [static, protected]
Initial value:
 array(
    'code',
    'state',
    'signed_request',
  )

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

Definition at line 139 of file base_facebook.php.

BaseFacebook.$fileUploadSupport = false [protected]

Definition at line 200 of file base_facebook.php.

BaseFacebook.$signedRequest [protected]

The data from the signed_request token.

Definition at line 180 of file base_facebook.php.

BaseFacebook.$state [protected]

A CSRF state variable to assist in the defense against CSRF attacks.

Definition at line 185 of file base_facebook.php.

BaseFacebook.$user [protected]

Definition at line 175 of file base_facebook.php.

const BaseFacebook.VERSION = '3.1.1'

Version.

Definition at line 123 of file base_facebook.php.


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