Class BaseFacebook - echiong/testRepo GitHub Wiki
##Class BaseFacebook
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.
###Direct known subclasses
<a href="Class Facebook.md">Facebookggg</a>
<b>Abstract</b><br />
Package: [[application<a href="Package application.libraries.md">libraries]]
Author:
Naitik Shah <[email protected]>
Located at application/libraries/facebook.php
##Methods summary
public __construct ( <array> $config )
Initialize a Facebook Application.
The configuration:
- appId: the application ID
<li>secret: the application secret</li>
<li>fileUpload: (optional) boolean indicating if file uploads are enabled</li>
Parameters
$config
<array>
$config The application configuration
public object setAppId ( string $appId )
Set the Application ID.
Parameters
$appId
string
$appId The Application ID
Returns
object
BaseFacebook
public string getAppId ( )
Get the Application ID.
Returns
string
the Application ID
public objetc setAppSecret ( string $appSecret )
Set the App Secret.
Parameters
$appSecret
string
$appSecret The App Secret
Returns
objetc
BaseFacebook
public string getAppSecret ( )
Get the App Secret.
Returns
string
the App Secret
public object setFileUploadSupport ( boolean $fileUploadSupport )
Set the file upload support status.
Parameters
$fileUploadSupport
boolean
$fileUploadSupport The file upload support status.
Returns
object
BaseFacebook
public boolean getFileUploadSupport ( )
Get the file upload support status.
Returns
boolean
true if and only if the server supports file upload.
public boolean useFileUploadSupport ( )
DEPRECATED! Please use getFileUploadSupport instead.
Get the file upload support status.
Returns
boolean
true if and only if the server supports file upload.
public object setAccessToken ( string $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
$access_token
string
$access_token an access token.
Returns
object
BaseFacebook
public string 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
protected string getUserAccessToken ( )
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.
public string 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.
public string getUser ( )
Get the UID of the connected user, or 0 if the Facebook user is not connected.
Returns
string
the UID if available.
protected integer getUserFromAvailableData ( )
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.
public string getLoginUrl ( array $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
<li>scope: comma separated list of requested extended perms</li>
Parameters
$params
array
$params Provide custom parameters
Returns
string
The URL for the login flow
public string getLogoutUrl ( array $params = array() )
Get a Logout URL suitable for use with redirects.
The parameters:
- next: the url to go to after a successful logout
Parameters
$params
array
$params Provide custom parameters
Returns
string
The URL for the logout flow
public string getLoginStatusUrl ( array $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
<li>no_session: the URL to go to if the user is not connected</li>
<li>no_user: the URL to go to if the user is not signed into facebook</li>
Parameters
$params
array
$params Provide custom parameters
Returns
string
The URL for the logout flow
public mixed api ( )
Make an API call.
Returns
mixed
The decoded response
protected string getSignedRequestCookieName ( )
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.
protected string getMetadataCookieName ( )
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.
Returns
string
the name of the cookie that would house metadata.
protected string|boolean getCode ( )
Get the authorization code from the query parameters, if it exists, and otherwise return false to signal no authorization code was discoverable.
Returns
string|boolean
The authorization code, or false if the authorization code could not be
determined.
protected integer getUserFromAccessToken ( )
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.
protected string getApplicationAccessToken ( )
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.
protected establishCSRFTokenState ( )
Lays down a CSRF state token for this process.
protected string|boolean getAccessTokenFromCode ( string $code, string $redirect_uri = null )
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
$code
string
$code An authorization code.
$redirect_uri
string
$redirect_uri uri for redirection.
Returns
string|boolean
An access token exchanged for the authorization code, or false if an access
token could not be generated.
protected mixed _restserver ( array $params )
Invoke the old restserver.php endpoint.
Parameters
$params
array
$params Method call object
Returns
mixed
The decoded response object
Throws
FacebookApiException
protected boolean isVideoPost ( string $path, string $method = 'GET' )
Return true if this is video post.
Parameters
$path
string
$path The path
$method
string
$method The http method (default 'GET')
Returns
boolean
true if this is video post
protected mixed _graph ( string $path, string $method = 'GET', array $params = array() )
Invoke the Graph API.
Parameters
$path
string
$path The path (required)
$method
string
$method The http method (default 'GET')
$params
array
$params The query/post data
Returns
mixed
The decoded response object
Throws
FacebookApiException
protected string _oauthRequest ( string $url, array $params )
Make a OAuth Request.
Parameters
$url
string
$url The path (required)
$params
array
$params The query/post data
Returns
string
The decoded response object
Throws
FacebookApiException
protected string makeRequest ( string $url, array $params, object $ch = null )
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
$url
string
$url The URL to make the request to
$params
array
$params The parameters to use for the POST body
$ch
object
$ch (CurlHandler) Initialized curl handle
Returns
string
The response text
protected array parseSignedRequest ( string $signed_request )
Parses a signed_request and validates the signature.
Parameters
$signed_request
string
$signed_request A signed token
Returns
array
The payload inside it or null if the sig is wrong
protected string getApiUrl ( string $method )
Build the URL for api given parameters.
Parameters
$method
string
$method String the method name.
Returns
string
The URL for the given parameters
protected string getUrl ( string $name, string $path = '', array $params = array() )
Build the URL for given domain alias, path and parameters.
Parameters
$name
string
$name The name of the domain
$path
string
$path Optional path (without a leading slash)
$params
array
$params Optional query parameters
Returns
string
The URL for the given parameters
protected string getCurrentUrl ( )
Returns the Current URL, stripping it of known FB parameters that should not persist.
Returns
string
The current URL
protected boolean shouldRetainParam ( string $param )
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
$param
string
$param A key or key/value pair within a URL's query (e.g. 'foo=a', 'foo=', or
'foo'.
Returns
boolean
protected throwAPIException ( array $result )
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.
Parameters
$result
array
$result A record storing the error message returned by a failed API call.
protected****static errorLog ( string $msg )
Prints to the error log if you aren't in command line mode.
Parameters
$msg
string
$msg Log message
protected****static string base64UrlDecode ( string $input )
Base64 encoding that doesn't need to be urlencode()ed. Exactly the same as base64_encode except it uses - instead of + _ instead of /
Parameters
$input
string
$input base64UrlEncoded string
Returns
string
public destroySession ( )
protected array getMetadataCookie ( )
Parses the metadata cookie that our Javascript API set
Returns
array
an array mapping key to value
abstract****protected setPersistentData ( string $key, array $value )
Stores the given ($key, $value) pair, so that future calls to getPersistentData($key) return $value. This call may be in another request.
Parameters
$key
string
$key Key
$value
array
$value Value
abstract****protected mixed getPersistentData ( string $key, boolean $default = false )
Get the data for $key, persisted by BaseFacebook::setPersistentData()
Parameters
$key
string
$key The key of the data to retrieve
$default
boolean
$default The default value to return if $key is not found
Returns
mixed
abstract****protected clearPersistentData ( string $key )
Clear the data with $key from the persistent storage
Parameters
$key
string
$key
abstract****protected clearAllPersistentData ( )
Clear all data from the persistent storage
<table class="summary" id="constants">
<caption>Constants summary</caption>
<tr data-order="VERSION" id="VERSION">
<td class="attributes"><code>string</code></td>
<td class="name"><code>
VERSION
'3.1.1'
<div class="description detailed">
Version.
</div>
</div></td>
</tr>
</table>
<table class="summary" id="properties">
<caption>Properties summary</caption>
<tr data-order="CURL_OPTS" id="$CURL_OPTS">
<td class="attributes"><code>
public static
array
</code></td>
<td class="name">
$CURL_OPTS
array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_USERAGENT => 'facebook-php-3.1',
)
<div class="description detailed">
Default options for curl.
</div>
</div></td>
</tr>
<tr data-order="DROP_QUERY_PARAMS" id="$DROP_QUERY_PARAMS">
<td class="attributes"><code>
protected static
array
</code></td>
<td class="name">
$DROP_QUERY_PARAMS
array(
'code',
'state',
'signed_request',
)
<div class="description detailed">
List of query parameters that get automatically dropped when rebuilding the current URL.
</div>
</div></td>
</tr>
<tr data-order="DOMAIN_MAP" id="$DOMAIN_MAP">
<td class="attributes"><code>
public static
array
</code></td>
<td class="name">
$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/',
)
<div class="description detailed">
Maps aliases to Facebook domains.
</div>
</div></td>
</tr>
<tr data-order="appId" id="$appId">
<td class="attributes"><code>
protected
string
</code></td>
<td class="name">
$appId
<div class="description detailed">
The Application ID.
</div>
</div></td>
</tr>
<tr data-order="appSecret" id="$appSecret">
<td class="attributes"><code>
protected
string
</code></td>
<td class="name">
$appSecret
<div class="description detailed">
The Application App Secret.
</div>
</div></td>
</tr>
<tr data-order="user" id="$user">
<td class="attributes"><code>
protected
integer
</code></td>
<td class="name">
$user
<div class="description detailed">
The ID of the Facebook user, or 0 if the user is logged out.
</div>
</div></td>
</tr>
<tr data-order="signedRequest" id="$signedRequest">
<td class="attributes"><code>
protected
mixed
</code></td>
<td class="name">
$signedRequest
<div class="description detailed">
The data from the signed_request token.
</div>
</div></td>
</tr>
<tr data-order="state" id="$state">
<td class="attributes"><code>
protected
mixed
</code></td>
<td class="name">
$state
<div class="description detailed">
A CSRF state variable to assist in the defense against CSRF attacks.
</div>
</div></td>
</tr>
<tr data-order="accessToken" id="$accessToken">
<td class="attributes"><code>
protected
string
</code></td>
<td class="name">
$accessToken
null
<div class="description detailed">
The OAuth access token received in exchange for a valid authorization code. null means the access token has yet to be determined.
</div>
</div></td>
</tr>
<tr data-order="fileUploadSupport" id="$fileUploadSupport">
<td class="attributes"><code>
protected
boolean
</code></td>
<td class="name">
$fileUploadSupport
false
<div class="description detailed">
Indicates if the CURL based @ syntax for file uploads is enabled.
</div>
</div></td>
</tr>
</table>