You are here

protected function FacebookAuth::initSdk in Social Auth Facebook 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Network/FacebookAuth.php \Drupal\social_auth_facebook\Plugin\Network\FacebookAuth::initSdk()
  2. 3.x src/Plugin/Network/FacebookAuth.php \Drupal\social_auth_facebook\Plugin\Network\FacebookAuth::initSdk()

Sets the underlying SDK library.

Return value

\Facebook\Facebook The initialized 3rd party library instance.

Throws

SocialApiException If the SDK library does not exist.

File

src/Plugin/Network/FacebookAuth.php, line 104

Class

FacebookAuth
Defines a Network Plugin for Social Auth Facebook.

Namespace

Drupal\social_auth_facebook\Plugin\Network

Code

protected function initSdk() {
  $class_name = '\\Facebook\\Facebook';
  if (!class_exists($class_name)) {
    throw new SocialApiException(sprintf('The PHP SDK for Facebook could not be found. Class: %s.', $class_name));
  }

  /* @var \Drupal\social_auth_facebook\Settings\FacebookAuthSettings $settings */
  $settings = $this->settings;
  if ($this
    ->validateConfig($settings)) {

    // All these settings are mandatory.
    $facebook_settings = [
      'app_id' => $settings
        ->getAppId(),
      'app_secret' => $settings
        ->getAppSecret(),
      'default_graph_version' => 'v' . $settings
        ->getGraphVersion(),
      'persistent_data_handler' => $this->persistentDataHandler,
      'http_client_handler' => $this
        ->getHttpClient(),
    ];
    return new Facebook($facebook_settings);
  }
  return FALSE;
}