You are here

public function FacebookAuthManager::getProfilePicture in Open Social 8.3

Same name and namespace in other branches
  1. 8.9 modules/custom/social_auth_facebook/src/FacebookAuthManager.php \Drupal\social_auth_facebook\FacebookAuthManager::getProfilePicture()
  2. 8 modules/custom/social_auth_facebook/src/FacebookAuthManager.php \Drupal\social_auth_facebook\FacebookAuthManager::getProfilePicture()
  3. 8.2 modules/custom/social_auth_facebook/src/FacebookAuthManager.php \Drupal\social_auth_facebook\FacebookAuthManager::getProfilePicture()
  4. 8.4 modules/custom/social_auth_facebook/src/FacebookAuthManager.php \Drupal\social_auth_facebook\FacebookAuthManager::getProfilePicture()
  5. 8.5 modules/custom/social_auth_facebook/src/FacebookAuthManager.php \Drupal\social_auth_facebook\FacebookAuthManager::getProfilePicture()
  6. 8.6 modules/custom/social_auth_facebook/src/FacebookAuthManager.php \Drupal\social_auth_facebook\FacebookAuthManager::getProfilePicture()
  7. 8.7 modules/custom/social_auth_facebook/src/FacebookAuthManager.php \Drupal\social_auth_facebook\FacebookAuthManager::getProfilePicture()
  8. 8.8 modules/custom/social_auth_facebook/src/FacebookAuthManager.php \Drupal\social_auth_facebook\FacebookAuthManager::getProfilePicture()

Returns URL of a profile picture.

Return value

string|null Absolute URL to a picture or Null if picture is not set.

Overrides AuthManagerInterface::getProfilePicture

File

modules/custom/social_auth_facebook/src/FacebookAuthManager.php, line 117

Class

FacebookAuthManager
Class FacebookAuthManager.

Namespace

Drupal\social_auth_facebook

Code

public function getProfilePicture() {
  $resolution = $this
    ->getPreferredResolution();
  $query = [
    'redirect' => 'false',
  ];
  if (is_array($resolution)) {
    $query += $resolution;
  }
  try {
    $graph_node = $this->sdk
      ->get('/me/picture?' . http_build_query($query))
      ->getGraphNode();
    $is_silhouette = (bool) $graph_node
      ->getField('is_silhouette');
    if ($is_silhouette) {
      return FALSE;
    }
    return $graph_node
      ->getField('url');
  } catch (FacebookResponseException $e) {
    $this->loggerFactory
      ->get('social_auth_facebook')
      ->error('Could not load Facebook profile picture: FacebookResponseException: @message', [
      '@message' => $e
        ->getMessage(),
    ]);
    return NULL;
  } catch (FacebookSDKException $e) {
    $this->loggerFactory
      ->get('social_auth_facebook')
      ->error('Could not load Facebook profile picture: FacebookSDKException: @message', [
      '@message' => $e
        ->getMessage(),
    ]);
    return NULL;
  }
  return FALSE;
}