public function SimpleFbConnectFbManager::getFbProfilePicUrl in Simple FB Connect 8.2
Same name and namespace in other branches
- 8.3 src/SimpleFbConnectFbManager.php \Drupal\simple_fb_connect\SimpleFbConnectFbManager::getFbProfilePicUrl()
Makes an API call to get the URL of user's Facebook profile picture.
Parameters
\Facebook\FacebookSession $fb_session: FacebookSession object.
Return value
string|false Absolute URL of the profile picture False on errors
File
- src/
SimpleFbConnectFbManager.php, line 245 - Contains \Drupal\simple_fb_connect\SimpleFbConnectFbManager.
Class
- SimpleFbConnectFbManager
- Contains all Simple FB Connect logic that is related to Facebook interaction.
Namespace
Drupal\simple_fb_connectCode
public function getFbProfilePicUrl(FacebookSession $fb_session) {
// Determine preferred resolution for the profile picture.
$resolution = $this
->getPreferredResolution();
// Generate FB API query.
$query = '/me/picture?redirect=false';
if (is_array($resolution)) {
$query .= '&width=' . $resolution['width'] . '&height=' . $resolution['height'];
}
// Call Graph API to request profile picture.
try {
$request = new FacebookRequest($fb_session, 'GET', $query);
$url = $request
->execute()
->getGraphObject()
->getProperty('url');
return $url;
} catch (FacebookRequestException $ex) {
$this->loggerFactory
->get('simple_fb_connect')
->error('Could not load Facebook profile picture URL. FacebookRequestException: @message', array(
'@message' => json_encode($ex
->getResponse()),
));
} catch (\Exception $ex) {
$this->loggerFactory
->get('simple_fb_connect')
->error('Could not load Facebook profile picture URL. Unhandled exception. Error details: @message', array(
'@message' => $ex
->getMessage(),
));
}
// Something went wrong and the picture could not be loaded.
return FALSE;
}