You are here

public function SimpleFbConnectFbManager::getFbProfilePic in Simple FB Connect 8.3

Makes an API call to get the URL of user's Facebook profile picture.

Return value

\Facebook\GraphNodes\GraphNode GraphNode object representing user's Facebook profile picture.

1 call to SimpleFbConnectFbManager::getFbProfilePic()
SimpleFbConnectFbManager::getFbProfilePicUrl in src/SimpleFbConnectFbManager.php
Returns the URL of user's Facebook profile picture.

File

src/SimpleFbConnectFbManager.php, line 230

Class

SimpleFbConnectFbManager
Contains all Simple FB Connect logic that is related to Facebook interaction.

Namespace

Drupal\simple_fb_connect

Code

public function getFbProfilePic() {

  // 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 {
    $graph_node = $this->facebook
      ->get($query)
      ->getGraphNode();
    return $graph_node;
  } catch (FacebookResponseException $ex) {
    $this->loggerFactory
      ->get('simple_fb_connect')
      ->error('Could not load Facebook profile picture. FacebookResponseException: @message', [
      '@message' => json_encode($ex
        ->getMessage()),
    ]);
  } catch (FacebookSDKException $ex) {
    $this->loggerFactory
      ->get('simple_fb_connect')
      ->error('Could not load Facebook profile picture. FacebookSDKException: @message', [
      '@message' => $ex
        ->getMessage(),
    ]);
  }

  // Something went wrong and the picture could not be loaded.
  return FALSE;
}