include/externalAPI/Facebook/facebook.php

Show: inherited
Table of Contents

\Facebook

Package: SugarCRM

Extends the BaseFacebook class with the intent of using PHP sessions to store user ids and access tokens.

Parent(s)
\BaseFacebook
Author
Naitik Shah  

Constants

Constant  FBSS_COOKIE_NAME = 'fbss'
Constant  FBSS_COOKIE_EXPIRE = 31556926
Constant  VERSION = '3.2.2'
inherited

Version.

Inherited from: \BaseFacebook::VERSION
Inherited_from
\BaseFacebook::VERSION  
Constant  SIGNED_REQUEST_ALGORITHM = 'HMAC-SHA256'
inherited

Signed Request Algorithm.

Inherited from: \BaseFacebook::SIGNED_REQUEST_ALGORITHM

Properties

Propertypublic  $CURL_OPTS= 'array( CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 60, CURLOPT_USERAGENT => 'facebook-php-3.2', )'
staticinherited

Default options for curl.

Inherited from: \BaseFacebook::$$CURL_OPTS
Default valuearray( CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 60, CURLOPT_USERAGENT => 'facebook-php-3.2', )Details
Type
n/a
Inherited_from
\BaseFacebook::$$CURL_OPTS  
Propertypublic  $DOMAIN_MAP= '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/', 'graph_video' => 'https://graph-video.facebook.com/', 'www' => 'https://www.facebook.com/', )'
staticinherited

Maps aliases to Facebook domains.

Inherited from: \BaseFacebook::$$DOMAIN_MAP
Default valuearray( 'api' => 'https://api.facebook.com/', 'api_video' => 'https://api-video.facebook.com/', 'api_read' => 'https://api-read.facebook.com/', 'graph' => 'https://graph.facebook.com/', 'graph_video' => 'https://graph-video.facebook.com/', 'www' => 'https://www.facebook.com/', )Details
Type
n/a
Inherited_from
\BaseFacebook::$$DOMAIN_MAP  
Propertyprotected  $DROP_QUERY_PARAMS= 'array( 'code', 'state', 'signed_request', )'
staticinherited

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

Inherited from: \BaseFacebook::$$DROP_QUERY_PARAMS
Default valuearray( 'code', 'state', 'signed_request', )Details
Type
n/a
Inherited_from
\BaseFacebook::$$DROP_QUERY_PARAMS  
Propertyprotectedstring  $accessToken= 'null'
inherited

The OAuth access token received in exchange for a valid authorization code. null means the access token has yet to be determined.

Inherited from: \BaseFacebook::$$accessToken
Default valuenullDetails
Type
string
Inherited_from
\BaseFacebook::$$accessToken  
Propertyprotectedstring  $appId= ''
inherited

The Application ID.

Inherited from: \BaseFacebook::$$appId
Details
Type
string
Inherited_from
\BaseFacebook::$$appId  
Propertyprotectedstring  $appSecret= ''
inherited

The Application App Secret.

Inherited from: \BaseFacebook::$$appSecret
Details
Type
string
Inherited_from
\BaseFacebook::$$appSecret  
Propertyprotectedboolean  $fileUploadSupport= 'false'
inherited

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

Inherited from: \BaseFacebook::$$fileUploadSupport
Default valuefalseDetails
Type
boolean
Inherited_from
\BaseFacebook::$$fileUploadSupport  
Propertyprotected  $kSupportedKeys= 'array('state', 'code', 'access_token', 'user_id')'
static
Default valuearray('state', 'code', 'access_token', 'user_id')Details
Type
n/a
Propertyprotected  $sharedSessionID= ''
Details
Type
n/a
Propertyprotected  $signedRequest= ''
inherited

The data from the signed_request token.

Inherited from: \BaseFacebook::$$signedRequest
Details
Type
n/a
Inherited_from
\BaseFacebook::$$signedRequest  
Propertyprotected  $state= ''
inherited

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

Inherited from: \BaseFacebook::$$state
Details
Type
n/a
Inherited_from
\BaseFacebook::$$state  
Propertyprotectedboolean  $trustForwarded= 'false'
inherited

Indicates if we trust HTTP_X_FORWARDED_* headers.

Inherited from: \BaseFacebook::$$trustForwarded
Default valuefalseDetails
Type
boolean
Inherited_from
\BaseFacebook::$$trustForwarded  
Propertyprotectedinteger  $user= ''
inherited

The ID of the Facebook user, or 0 if the user is logged out.

Inherited from: \BaseFacebook::$$user
Details
Type
integer
Inherited_from
\BaseFacebook::$$user  

Methods

methodpublic__construct( Array $config ) : void

Identical to the parent constructor, except that we start a PHP session to store the user ID and access token if during the course of execution we discover them.

The configuration: - appId: the application ID - secret: the application secret - fileUpload: (optional) boolean indicating if file uploads are enabled

Parameters
Name Type Description
$config Array

the application configuration. Additionally accepts "sharedSession" as a boolean to turn on a secondary cookie for environments with a shared session (that is, your app shares the domain with other apps).

Details
See
\BaseFacebook::__construct  
methodprotected_graph( string $path, string $method = 'GET', array $params = array() ) : mixed
inherited

Invoke the Graph API.

Inherited from: \BaseFacebook::_graph()
Parameters
Name Type Description
$path string

The path (required)

$method string

The http method (default 'GET')

$params array

The query/post data

Returns
Type Description
mixed The decoded response object
Throws
Exception Description
\FacebookApiException
methodprotected_oauthRequest( string $url, array $params ) : string
inherited

Make a OAuth Request.

Inherited from: \BaseFacebook::_oauthRequest()
Parameters
Name Type Description
$url string

The path (required)

$params array

The query/post data

Returns
Type Description
string The decoded response object
Throws
Exception Description
\FacebookApiException
methodprotected_restserver( array $params ) : mixed
inherited

Invoke the old restserver.php endpoint.

Inherited from: \BaseFacebook::_restserver()
Parameters
Name Type Description
$params array

Method call object

Returns
Type Description
mixed The decoded response object
Throws
Exception Description
\FacebookApiException
methodpublicapi( ) : mixed
inherited

Make an API call.

Inherited from: \BaseFacebook::api()
Returns
Type Description
mixed The decoded response
methodprotectedbase64UrlDecode( string $input ) : string
staticinherited

Base64 encoding that doesn't need to be urlencode()ed.

Inherited from: \BaseFacebook::base64UrlDecode()

Exactly the same as base64_encode except it uses - instead of + _ instead of / No padded =

Parameters
Name Type Description
$input string

base64UrlEncoded string

Returns
Type Description
string
methodprotectedbase64UrlEncode( string $input ) : string
staticinherited

Base64 encoding that doesn't need to be urlencode()ed.

Inherited from: \BaseFacebook::base64UrlEncode()

Exactly the same as base64_encode except it uses - instead of + _ instead of /

Parameters
Name Type Description
$input string

string

Returns
Type Description
string base64Url encoded string
methodprotectedclearAllPersistentData( ) : void

Clear all data from the persistent storage

methodprotectedclearPersistentData( string $key ) : void

Clear the data with $key from the persistent storage

Parameters
Name Type Description
$key string
methodprotectedconstructSessionVariableName(  $key ) : void

Parameters
Name Type Description
$key
methodprotecteddeleteSharedSessionCookie( ) : void

methodpublicdestroySession( ) : void
inherited

Destroy the current session

Inherited from: \BaseFacebook::destroySession()
methodprotectedendsWith(  $big,  $small ) : void
staticinherited

Inherited from: \BaseFacebook::endsWith()
Parameters
Name Type Description
$big
$small
methodprotectederrorLog( string $msg ) : void
staticinherited

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

Inherited from: \BaseFacebook::errorLog()
Parameters
Name Type Description
$msg string

Log message

methodprotectedestablishCSRFTokenState( ) : void
inherited

Lays down a CSRF state token for this process.

Inherited from: \BaseFacebook::establishCSRFTokenState()
methodpublicgetAccessToken( ) : string
inherited

Determines the access token that should be used for API calls.

Inherited from: \BaseFacebook::getAccessToken()

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
Type Description
string The access token
methodprotectedgetAccessTokenFromCode( string $code,  $redirect_uri = null ) : mixed
inherited

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.

Inherited from: \BaseFacebook::getAccessTokenFromCode()
Parameters
Name Type Description
$code string

An authorization code.

$redirect_uri
Returns
Type Description
mixed An access token exchanged for the authorization code, or false if an access token could not be generated.
methodpublicgetApiSecret( ) : string
inherited

Get the App Secret.

Inherited from: \BaseFacebook::getApiSecret()
Returns
Type Description
string the App Secret
methodprotectedgetApiUrl( \$method $method ) : string
inherited

Build the URL for api given parameters.

Inherited from: \BaseFacebook::getApiUrl()
Parameters
Name Type Description
$method \$method

String the method name.

Returns
Type Description
string The URL for the given parameters
methodpublicgetAppId( ) : string
inherited

Get the Application ID.

Inherited from: \BaseFacebook::getAppId()
Returns
Type Description
string the Application ID
methodpublicgetAppSecret( ) : string
inherited

Get the App Secret.

Inherited from: \BaseFacebook::getAppSecret()
Returns
Type Description
string the App Secret
methodprotectedgetApplicationAccessToken( ) : string
inherited

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

Inherited from: \BaseFacebook::getApplicationAccessToken()
Returns
Type Description
string The application access token, useful for gathering public information about users and applications.
methodprotectedgetBaseDomain( ) : void
inherited

Get the base domain used for the cookie.

Inherited from: \BaseFacebook::getBaseDomain()
methodprotectedgetCode( ) : mixed
inherited

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

Inherited from: \BaseFacebook::getCode()
Returns
Type Description
mixed The authorization code, or false if the authorization code could not be determined.
methodprotectedgetCurrentUrl( ) : string
inherited

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

Inherited from: \BaseFacebook::getCurrentUrl()
Returns
Type Description
string The current URL
methodpublicgetFileUploadSupport( ) : boolean
inherited

Get the file upload support status.

Inherited from: \BaseFacebook::getFileUploadSupport()
Returns
Type Description
boolean true if and only if the server supports file upload.
methodprotectedgetHttpHost( ) : void
inherited

Inherited from: \BaseFacebook::getHttpHost()
methodprotectedgetHttpProtocol( ) : void
inherited

Inherited from: \BaseFacebook::getHttpProtocol()
methodpublicgetLoginStatusUrl( array $params = array() ) : string
inherited

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

Inherited from: \BaseFacebook::getLoginStatusUrl()

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
Name Type Description
$params array

Provide custom parameters

Returns
Type Description
string The URL for the logout flow
methodpublicgetLoginUrl( array $params = array() ) : string
inherited

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.

Inherited from: \BaseFacebook::getLoginUrl()

The parameters: - redirect_uri: the url to go to after a successful login - scope: comma separated list of requested extended perms

Parameters
Name Type Description
$params array

Provide custom parameters

Returns
Type Description
string The URL for the login flow
methodpublicgetLogoutUrl( array $params = array() ) : string
inherited

Get a Logout URL suitable for use with redirects.

Inherited from: \BaseFacebook::getLogoutUrl()

The parameters: - next: the url to go to after a successful logout

Parameters
Name Type Description
$params array

Provide custom parameters

Returns
Type Description
string The URL for the logout flow
methodprotectedgetMetadataCookie( ) : \an
inherited

Parses the metadata cookie that our Javascript API set

Inherited from: \BaseFacebook::getMetadataCookie()
Returns
Type Description
\an array mapping key to value
methodprotectedgetMetadataCookieName( ) : string
inherited

Constructs and returns the name of the coookie that potentially contain metadata. The cookie is not set by the BaseFacebook class, but it may be set by the JavaScript SDK.

Inherited from: \BaseFacebook::getMetadataCookieName()
Returns
Type Description
string the name of the cookie that would house metadata.
methodprotectedgetPersistentData( string $key, boolean $default = false ) : mixed

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

Parameters
Name Type Description
$key string

The key of the data to retrieve

$default boolean

The default value to return if $key is not found

Returns
Type Description
mixed
methodprotectedgetSharedSessionCookieName( ) : void

methodpublicgetSignedRequest( ) : string
inherited

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

Inherited from: \BaseFacebook::getSignedRequest()
Returns
Type Description
string the signed request, if available, or null otherwise.
methodprotectedgetSignedRequestCookieName( ) : string
inherited

Constructs and returns the name of the cookie that potentially houses the signed request for the app user.

Inherited from: \BaseFacebook::getSignedRequestCookieName()

The cookie is not set by the BaseFacebook class, but it may be set by the JavaScript SDK.

Returns
Type Description
string the name of the cookie that would house the signed request value.
methodprotectedgetUrl( \$name $name, \$path $path = '', \$params $params = array() ) : string
inherited

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

Inherited from: \BaseFacebook::getUrl()
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

Returns
Type Description
string The URL for the given parameters
methodpublicgetUser( ) : string
inherited

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

Inherited from: \BaseFacebook::getUser()
Returns
Type Description
string the UID if available.
methodprotectedgetUserAccessToken( ) : string
inherited

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.

Inherited from: \BaseFacebook::getUserAccessToken()
Returns
Type Description
string A valid user access token, or false if one could not be determined.
methodprotectedgetUserFromAccessToken( ) : integer
inherited

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.

Inherited from: \BaseFacebook::getUserFromAccessToken()
Returns
Type Description
integer Returns the UID of the Facebook user, or 0 if the Facebook user could not be determined.
methodprotectedgetUserFromAvailableData( ) : integer
inherited

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.

Inherited from: \BaseFacebook::getUserFromAvailableData()
Returns
Type Description
integer The id of the connected Facebook user, or 0 if no such user exists.
methodprotectedinitSharedSession( ) : void

methodprotectedisAllowedDomain(  $big,  $small ) : void
staticinherited

Inherited from: \BaseFacebook::isAllowedDomain()
Parameters
Name Type Description
$big
$small
methodprotectedisVideoPost( string $path, string $method = 'GET' ) : boolean
inherited

Return true if this is video post.

Inherited from: \BaseFacebook::isVideoPost()
Parameters
Name Type Description
$path string

The path

$method string

The http method (default 'GET')

Returns
Type Description
boolean true if this is video post
methodprotectedmakeRequest( string $url, array $params, \CurlHandler $ch = null ) : string
inherited

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.

Inherited from: \BaseFacebook::makeRequest()
Parameters
Name Type Description
$url string

The URL to make the request to

$params array

The parameters to use for the POST body

$ch \CurlHandler

Initialized curl handle

Returns
Type Description
string The response text
methodprotectedmakeSignedRequest( array $data ) : string
inherited

Makes a signed_request blob using the given data.

Inherited from: \BaseFacebook::makeSignedRequest()
Parameters
Name Type Description
$data array

The data array.

Returns
Type Description
string The signed request.
methodprotectedparseSignedRequest( string $signed_request ) : array
inherited

Parses a signed_request and validates the signature.

Inherited from: \BaseFacebook::parseSignedRequest()
Parameters
Name Type Description
$signed_request string

A signed token

Returns
Type Description
array The payload inside it or null if the sig is wrong
methodpublicsetAccessToken( string $access_token ) : \BaseFacebook
inherited

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.

Inherited from: \BaseFacebook::setAccessToken()
Parameters
Name Type Description
$access_token string

an access token.

Returns
Type Description
\BaseFacebook
methodpublicsetApiSecret( string $apiSecret ) : \BaseFacebook
inherited

Set the App Secret.

Inherited from: \BaseFacebook::setApiSecret()
Parameters
Name Type Description
$apiSecret string

The App Secret

Returns
Type Description
\BaseFacebook
methodpublicsetAppId( string $appId ) : \BaseFacebook
inherited

Set the Application ID.

Inherited from: \BaseFacebook::setAppId()
Parameters
Name Type Description
$appId string

The Application ID

Returns
Type Description
\BaseFacebook
methodpublicsetAppSecret( string $appSecret ) : \BaseFacebook
inherited

Set the App Secret.

Inherited from: \BaseFacebook::setAppSecret()
Parameters
Name Type Description
$appSecret string

The App Secret

Returns
Type Description
\BaseFacebook
methodpublicsetExtendedAccessToken( ) : void
inherited

Extend an access token, while removing the short-lived token that might have been generated via client-side flow. Thanks to http://bit.ly/b0Pt0H for the workaround.

Inherited from: \BaseFacebook::setExtendedAccessToken()
methodpublicsetFileUploadSupport( boolean $fileUploadSupport ) : \BaseFacebook
inherited

Set the file upload support status.

Inherited from: \BaseFacebook::setFileUploadSupport()
Parameters
Name Type Description
$fileUploadSupport boolean

The file upload support status.

Returns
Type Description
\BaseFacebook
methodprotectedsetPersistentData( string $key, array $value ) : void

Provides the implementations of the inherited abstract methods. The implementation uses PHP sessions to maintain a store for authorization codes, user ids, CSRF states, and access tokens.

Parameters
Name Type Description
$key string
$value array
methodprotectedshouldRetainParam( string $param ) : boolean
inherited

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.

Inherited from: \BaseFacebook::shouldRetainParam()
Parameters
Name Type Description
$param string

A key or key/value pair within a URL's query (e.g. 'foo=a', 'foo=', or 'foo'.

Returns
Type Description
boolean
methodprotectedthrowAPIException( \$result $result ) : void
inherited

Analyzes the supplied result to see if it was thrown because the access token is no longer valid. If that is the case, then we destroy the session.

Inherited from: \BaseFacebook::throwAPIException()
Parameters
Name Type Description
$result \$result

array A record storing the error message returned by a failed API call.

methodpublicuseFileUploadSupport( ) : boolean
inherited

DEPRECATED! Please use getFileUploadSupport instead.

Inherited from: \BaseFacebook::useFileUploadSupport()

Get the file upload support status.

Returns
Type Description
boolean true if and only if the server supports file upload.
Documentation was generated by DocBlox 0.18.1.