include/externalAPI/Facebook/FacebookLib.php

Show: inherited
Table of Contents

\FacebookApiException

Package: SugarCRM

Thrown when an API call returns an exception.

Parent(s)
\Exception
Author
Naitik Shah  

Properties

Propertyprotected  $result= ''

The result from the API server that represents the exception information.

Details
Type
n/a

Methods

methodpublic__construct( Array $result ) : void

Make a new API Exception with the given result.

Parameters
Name Type Description
$result Array

the result from the API server

methodpublic__toString( ) : void

To make debugging easier.

Details
Returns
String the string representation of the error  
methodpublicgetResult( ) : void

Return the associated result object returned by the API server.

Details
Returns
Array the result from the API server  
methodpublicgetType( ) : String

Returns the associated type for the error. This will default to 'Exception' when a type is not available.

Returns
Type Description
String

\FacebookLib

Package: SugarCRM

Provides access to the Facebook Platform.

Author
Naitik Shah  

Constants

Constant  VERSION = '2.0.6'

Version.

Properties

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

Default options for curl.

Default valuearray( CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 60, CURLOPT_USERAGENT => 'facebook-php-2.0', )Details
Type
n/a
Propertypublic  $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/', )'
static

Maps aliases to Facebook domains.

Default valuearray( '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
Propertyprotected  $DROP_QUERY_PARAMS= 'array( 'session', 'signed_request', )'
static

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

Default valuearray( 'session', 'signed_request', )Details
Type
n/a
Propertyprotected  $apiSecret= ''

The Application API Secret.

Details
Type
n/a
Propertyprotected  $appId= ''

The Application ID.

Details
Type
n/a
Propertyprotected  $baseDomain= ''''

Base domain for the Cookie.

Default value''Details
Type
n/a
Propertyprotected  $cookieSupport= 'false'

Indicates if Cookie support should be enabled.

Default valuefalseDetails
Type
n/a
Propertyprotected  $session= ''

The active user session, if one is available.

Details
Type
n/a
Propertyprotected  $sessionLoaded= 'false'

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

Default valuefalseDetails
Type
n/a
Propertyprotected  $signedRequest= ''

The data from the signed_request token.

Details
Type
n/a

Methods

methodpublic__construct( Array $config ) : void

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

Parameters
Name Type Description
$config Array

the application configuration

methodprotected_graph( String $path, String $method = 'GET', Array $params = array() ) : \the

Invoke the Graph API.

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
\the decoded response object
Throws
Exception Description
\FacebookApiException
methodprotected_oauthRequest(  $url, Array $params ) : \the

Make a OAuth Request

Parameters
Name Type Description
$url
$params Array

the query/post data

Returns
Type Description
\the decoded response object
Throws
Exception Description
\FacebookApiException
methodprotected_restserver( Array $params ) : \the

Invoke the old restserver.php endpoint.

Parameters
Name Type Description
$params Array

method call object

Returns
Type Description
\the decoded response object
Throws
Exception Description
\FacebookApiException
methodpublicapi( ) : \the

Make an API call.

Returns
Type Description
\the decoded response
methodprotectedbase64UrlDecode( String $input ) : void
static

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

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

Parameters
Name Type Description
$input String

base64UrlEncodeded string

methodprotectedcreateSessionFromSignedRequest( Array $data ) : Array

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
Name Type Description
$data Array

the output of getSignedRequest

Returns
Type Description
Array Something that will work as a session
methodprotectederrorLog( String $msg ) : void
static

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

Parameters
Name Type Description
$msg String

log message

methodprotectedgenerateSignature( Array $params, String $secret ) : String
static

Generate a signature for the given params and secret.

Parameters
Name Type Description
$params Array

the parameters to sign

$secret String

the secret to sign with

Returns
Type Description
String the generated signature
methodpublicgetAccessToken( ) : String

Gets a OAuth access token.

Returns
Type Description
String the access token
methodpublicgetApiSecret( ) : String

Get the API Secret.

Returns
Type Description
String the API Secret
methodprotectedgetApiUrl( \$method $method ) : String

Build the URL for api given parameters.

Parameters
Name Type Description
$method \$method

String the method name.

Returns
Type Description
String the URL for the given parameters
methodpublicgetAppId( ) : String

Get the Application ID.

Returns
Type Description
String the Application ID
methodpublicgetBaseDomain( ) : String

Get the base domain for the Cookie.

Returns
Type Description
String the base domain
methodprotectedgetCurrentUrl( ) : String

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

Returns
Type Description
String the current URL
methodpublicgetLoginStatusUrl( Array $params = array() ) : String

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

provide custom parameters

Returns
Type Description
String the URL for the logout flow
methodpublicgetLoginUrl( Array $params = array() ) : String

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

provide custom parameters

Returns
Type Description
String the URL for the login flow
methodpublicgetLogoutUrl( Array $params = array() ) : String

Get a Logout URL suitable for use with redirects.

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
methodpublicgetSession( ) : Array

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

Returns
Type Description
Array the session
methodprotectedgetSessionCookieName( ) : String

The name of the Cookie that contains the session.

Returns
Type Description
String the cookie name
methodpublicgetSignedRequest( ) : String

Get the data from a signed_request token

Returns
Type Description
String the base domain
methodprotectedgetUrl( \$name $name, \$path $path = '', \$params $params = array() ) : String

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

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

Get the UID from the session.

Returns
Type Description
String the UID if available
methodprotectedmakeRequest( String $url, Array $params, \CurlHandler $ch = null ) : String

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
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

Returns
Type Description
String the response text
methodprotectedparseSignedRequest( String $signed_request ) : Array

Parses a signed_request and validates the signature.

Then saves it in $this->signed_data

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
methodpublicsetApiSecret(  $apiSecret ) : void

Set the API Secret.

Parameters
Name Type Description
$apiSecret
methodpublicsetAppId( String $appId ) : void

Set the Application ID.

Parameters
Name Type Description
$appId String

the Application ID

methodpublicsetBaseDomain( String $domain ) : void

Set the base domain for the Cookie.

Parameters
Name Type Description
$domain String

the base domain

methodprotectedsetCookieFromSession( Array $session = null ) : void

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
Name Type Description
$session Array

the session to use for setting the cookie

methodpublicsetCookieSupport( Boolean $cookieSupport ) : void

Set the Cookie Support status.

Parameters
Name Type Description
$cookieSupport Boolean

the Cookie Support status

methodpublicsetSession( Array $session = null, Boolean $write_cookie = true ) : void

Set the Session.

Parameters
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.

methodpublicuseCookieSupport( ) : Boolean

Get the Cookie Support status.

Returns
Type Description
Boolean the Cookie Support status
methodprotectedvalidateSessionObject( Array $session ) : Array

Validates a session_version=3 style session object.

Parameters
Name Type Description
$session Array

the session object

Returns
Type Description
Array the session object if it validates, null otherwise
Documentation was generated by DocBlox 0.18.1.