This document refers to a feature that was removed after PHP SDK 4.0.0.
PHP SDK Version
5.0.0

GraphObject for the Facebook SDK for PHP

Represents an object returned by the Graph API.

Facebook\GraphObject

This base class has several subclasses, some are provided by default:

GraphUser
GraphLocation
GraphSessionInfo

Usage:

// Get the base class GraphObject from the response
$object = $response->getGraphObject();

// Get the response typed as a GraphUser
$user = $response->getGraphObject(GraphUser::className());
// or convert the base object previously accessed
// $user = $object->cast(GraphUser::className());

// Get the response typed as a GraphLocation
$loc = $response->getGraphObject(GraphLocation::className());
// or convert the base object previously accessed
// $loc = $object->cast(GraphLocation::className());

// User example
echo $object->getProperty('name');
echo $user->getName();

// Location example
echo $object->getProperty('country');
echo $loc->getCountry();

// SessionInfo example
$info = $session->getSessionInfo());
echo $info->getxpiresAt();

GraphObject Instance Methods

cast

cast(string $type)
Returns a new instance of a GraphObject subclass with this objects underlying data.

asArray

asArray()
Returns the raw representation (associative arrays, nested) of this objects underlying data.

getProperty

getProperty(string $name, string $type = 'Facebook\GraphObject')
Gets the value of a named key for this graph object. If the value is a scalar (string, number, etc.) it will be returned. If it's an associative array, it will be returned as a GraphObject cast to the appropriate subclass type if provided.

getPropertyAsArray

getPropertyAsArray()
Gets the contents of a named array property on this graph object. If the values are scalar (strings, numbers, etc.) they will be returned as-is. If the values are associative arrays, they will be returned as GraphObjects cast to the appropriate subclass type if provided.

getPropertyNames

getPropertyNames()
Returns an array with the names of all properties present on this graph object.

GraphUser Instance Methods

getId

getId()
Returns the id property for the user as a string if present.

getName

getName()
Returns the name property for the user as a string if present.

getFirstName

getFirstName()
Returns the first_name property for the user as a string if present.

getMiddleName

getMiddleName()
Returns the middle_name property for the user as a string if present.

getLastName

getLastName()
Returns the last_name property for the user as a string if present.

getLink()
Returns the link property for the user as a string if present.

getBirthday

getBirthday()
Returns the birthday property for the user as a \DateTime if present.

getLocation

getLocation()
Returns the location property for the user as a Facebook\GraphLocation if present.'

GraphLocation Instance Methods

getStreet

getStreet()
Returns the street property for the location as a string if present.

getCity

getCity()
Returns the city property for the location as a string if present.

getState

getState()
Returns the state property for the location as a string if present.

getCountry

getCountry()
Returns the country property for the location as a string if present.

getZip

getZip()
Returns the zip property for the user as a location if present.

getLatitude

getLatitude()
Returns the latitude property for the location as a float if present.

getLongitude

getLongitude()
Returns the latitude property for the location as a float if present.

GraphSessionInfo Instance Methods

getAppId

getAppId()
Returns the app_id property for the session as a string if present.

getApplication

getApplication()
Returns the application property for the session as a string if present.

getExpiresAt

getExpiresAt()
Returns the expires_at property for the session as a \DateTime if present.

getIsValid

getIsValid()
Returns the is_valid property for the session as a boolean if present.

getIssuedAt

getIssuedAt()
Returns the issued_at property for the session as a \DateTime if present.

getScopes

getScopes()
Returns the scopes property for the session as an array if present.

getId

getId()
Returns the user_id property for the session as a string if present.