include/externalAPI/Facebook/FacebookLib.php
\FacebookApiException
Thrown when an API call returns an exception.
- Parent(s)
- \Exception
- Author
- Naitik Shah
Properties
Methods

__construct(
Array $result
)
:
voidMake a new API Exception with the given result.
| Name | Type | Description |
|---|---|---|
| $result | Array | the result from the API server |

__toString(
)
:
voidTo make debugging easier.
- Returns
- String the string representation of the error

getResult(
)
:
voidReturn the associated result object returned by the API server.
- Returns
- Array the result from the API server
\FacebookLib
Provides access to the Facebook Platform.
- Author
- Naitik Shah
Constants
Properties

$CURL_OPTS= 'array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_USERAGENT => 'facebook-php-2.0',
)'
Default options for curl.
array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_USERAGENT => 'facebook-php-2.0',
)Details- Type
- n/a

$DOMAIN_MAP= '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.
array(
'api' => 'https://api.facebook.com/',
'api_read' => 'https://api-read.facebook.com/',
'graph' => 'https://graph.facebook.com/',
'www' => 'https://www.facebook.com/',
)Details- Type
- n/a

$DROP_QUERY_PARAMS= 'array(
'session',
'signed_request',
)'
List of query parameters that get automatically dropped when rebuilding the current URL.
array(
'session',
'signed_request',
)Details- Type
- n/a

$cookieSupport= 'false'
Indicates if Cookie support should be enabled.
falseDetails- Type
- n/a

$sessionLoaded= 'false'
Indicates that we already loaded the session as best as we could.
falseDetails- Type
- n/a
Methods

__construct(
Array $config
)
:
voidInitialize 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
| Name | Type | Description |
|---|---|---|
| $config | Array | the application configuration |

_graph(
String $path, String $method
=
'GET', Array $params
=
array()
)
:
\theInvoke the Graph API.
| Name | Type | Description |
|---|---|---|
| $path | String | the path (required) |
| $method | String | the http method (default 'GET') |
| $params | Array | the query/post data |
| Type | Description |
|---|---|
| \the | decoded response object |
| Exception | Description |
|---|---|
| \FacebookApiException |

_oauthRequest(
$url, Array $params
)
:
\theMake a OAuth Request
| Name | Type | Description |
|---|---|---|
| $url | ||
| $params | Array | the query/post data |
| Type | Description |
|---|---|
| \the | decoded response object |
| Exception | Description |
|---|---|
| \FacebookApiException |

_restserver(
Array $params
)
:
\theInvoke the old restserver.php endpoint.
| Name | Type | Description |
|---|---|---|
| $params | Array | method call object |
| Type | Description |
|---|---|
| \the | decoded response object |
| Exception | Description |
|---|---|
| \FacebookApiException |

base64UrlDecode(
String $input
)
:
voidBase64 encoding that doesn't need to be urlencode()ed.
Exactly the same as base64_encode except it uses - instead of + _ instead of /
| Name | Type | Description |
|---|---|---|
| $input | String | base64UrlEncodeded string |

createSessionFromSignedRequest(
Array $data
)
:
ArrayReturns something that looks like our JS session object from the signed token's data
TODO: Nuke this once the login flow uses OAuth2
| Name | Type | Description |
|---|---|---|
| $data | Array | the output of getSignedRequest |
| Type | Description |
|---|---|
| Array | Something that will work as a session |

errorLog(
String $msg
)
:
voidPrints to the error log if you aren't in command line mode.
| Name | Type | Description |
|---|---|---|
| $msg | String | log message |

generateSignature(
Array $params, String $secret
)
:
StringGenerate a signature for the given params and secret.
| Name | Type | Description |
|---|---|---|
| $params | Array | the parameters to sign |
| $secret | String | the secret to sign with |
| Type | Description |
|---|---|
| String | the generated signature |

getAccessToken(
)
:
StringGets a OAuth access token.
| Type | Description |
|---|---|
| String | the access token |

getApiUrl(
\$method $method
)
:
StringBuild the URL for api given parameters.
| Name | Type | Description |
|---|---|---|
| $method | \$method | String the method name. |
| Type | Description |
|---|---|
| String | the URL for the given parameters |

getBaseDomain(
)
:
StringGet the base domain for the Cookie.
| Type | Description |
|---|---|
| String | the base domain |

getCurrentUrl(
)
:
StringReturns the Current URL, stripping it of known FB parameters that should not persist.
| Type | Description |
|---|---|
| String | the current URL |

getLoginStatusUrl(
Array $params
=
array()
)
:
StringGet 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
| Name | Type | Description |
|---|---|---|
| $params | Array | provide custom parameters |
| Type | Description |
|---|---|
| String | the URL for the logout flow |

getLoginUrl(
Array $params
=
array()
)
:
StringGet 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"
| Name | Type | Description |
|---|---|---|
| $params | Array | provide custom parameters |
| Type | Description |
|---|---|
| String | the URL for the login flow |

getLogoutUrl(
Array $params
=
array()
)
:
StringGet a Logout URL suitable for use with redirects.
The parameters: - next: the url to go to after a successful logout
| Name | Type | Description |
|---|---|---|
| $params | Array | provide custom parameters |
| Type | Description |
|---|---|
| String | the URL for the logout flow |

getSession(
)
:
ArrayGet the session object. This will automatically look for a signed session sent via the signed_request, Cookie or Query Parameters if needed.
| Type | Description |
|---|---|
| Array | the session |

getSessionCookieName(
)
:
StringThe name of the Cookie that contains the session.
| Type | Description |
|---|---|
| String | the cookie name |

getSignedRequest(
)
:
StringGet the data from a signed_request token
| Type | Description |
|---|---|
| String | the base domain |

getUrl(
\$name $name, \$path $path
=
'', \$params $params
=
array()
)
:
StringBuild the URL for given domain alias, path and parameters.
| Name | Type | Description |
|---|---|---|
| $name | \$name | String the name of the domain |
| $path | \$path | String optional path (without a leading slash) |
| $params | \$params | Array optional query parameters |
| Type | Description |
|---|---|
| String | the URL for the given parameters |

getUser(
)
:
StringGet the UID from the session.
| Type | Description |
|---|---|
| String | the UID if available |

makeRequest(
String $url, Array $params, \CurlHandler $ch
=
null
)
:
StringMakes 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.
| Name | Type | Description |
|---|---|---|
| $url | String | the URL to make the request to |
| $params | Array | the parameters to use for the POST body |
| $ch | \CurlHandler | optional initialized curl handle |
| Type | Description |
|---|---|
| String | the response text |

parseSignedRequest(
String $signed_request
)
:
ArrayParses a signed_request and validates the signature.
Then saves it in $this->signed_data
| Name | Type | Description |
|---|---|---|
| $signed_request | String | A signed token |
| Type | Description |
|---|---|
| Array | the payload inside it or null if the sig is wrong |

setAppId(
String $appId
)
:
voidSet the Application ID.
| Name | Type | Description |
|---|---|---|
| $appId | String | the Application ID |

setBaseDomain(
String $domain
)
:
voidSet the base domain for the Cookie.
| Name | Type | Description |
|---|---|---|
| $domain | String | the base domain |

setCookieFromSession(
Array $session
=
null
)
:
voidSet a JS Cookie based on the _passed in_ session. It does not use the currently stored session -- you need to explicitly pass it in.
| Name | Type | Description |
|---|---|---|
| $session | Array | the session to use for setting the cookie |

setCookieSupport(
Boolean $cookieSupport
)
:
voidSet the Cookie Support status.
| Name | Type | Description |
|---|---|---|
| $cookieSupport | Boolean | the Cookie Support status |

setSession(
Array $session
=
null, Boolean $write_cookie
=
true
)
:
voidSet the Session.
| Name | Type | Description |
|---|---|---|
| $session | Array | the session |
| $write_cookie | Boolean | indicate if a cookie should be written. this value is ignored if cookie support has been disabled. |

useCookieSupport(
)
:
BooleanGet the Cookie Support status.
| Type | Description |
|---|---|
| Boolean | the Cookie Support status |