You are here

class DrupalClient in Facebook Instant Articles 7

Same name and namespace in other branches
  1. 7.2 modules/fb_instant_articles_api/src/DrupalClient.php \Drupal\fb_instant_articles_api\DrupalClient

Encapsulates any Drupal-specific logic when using the Client.

Class DrupalClient @package Drupal\fb_instant_articles_api

Hierarchy

  • class \Drupal\fb_instant_articles_api\DrupalClient extends \Facebook\InstantArticles\Client\Client

Expanded class hierarchy of DrupalClient

File

modules/fb_instant_articles_api/src/DrupalClient.php, line 19
Contains \Drupal\fb_instant_articles_api\DrupalClient.

Namespace

Drupal\fb_instant_articles_api
View source
class DrupalClient extends Client {

  /**
   * Facebook Graph API Permision Error Code
   **/
  const FB_INSTANT_ARTICLES_ERROR_CODE_PERMISSION = 200;

  /**
   * Facebook Graph API Page Not Approved Error Code
   **/
  const FB_INSTANT_ARTICLES_ERROR_CODE_PAGE_NOT_APPROVED = 1888205;

  /**
   * Get an Instant Articles API client instance configured with sitewide Drupal settings
   */
  public static function get() {
    $appID = variable_get('fb_instant_articles_api_app_id');
    $appSecret = variable_get('fb_instant_articles_api_app_secret');
    $accessToken = variable_get('fb_instant_articles_api_access_token');
    $pageID = variable_get('fb_instant_articles_page_id');
    $developmentMode = (bool) variable_get('fb_instant_articles_api_development_mode', FALSE);
    return parent::create($appID, $appSecret, $accessToken, $pageID, $developmentMode);
  }

  /**
   * {@inheritdoc}
   *
   * Additionally try to catch an attempted import call.
   *
   * @todo Revisit this try/catch wrapper if the API gives an API option to see
   *   if the page has passed review. This may in fact be the best way, but that
   *   is still in discussion by the Facebook team.
   */
  public function importArticle($article, $takeLive = FALSE) {
    try {
      parent::importArticle($article, $takeLive);
    } catch (FacebookResponseException $e) {

      // If this was an authorization exception and the error code indicates
      // that the page has not yet passed review, try posting the article
      // unpublished. Only try again if the article was intended to be
      // published, so we don't try to post unpublished twice.
      if ($e
        ->getCode() === self::FB_INSTANT_ARTICLES_ERROR_CODE_PERMISSION && $e
        ->getSubErrorCode() === self::FB_INSTANT_ARTICLES_ERROR_CODE_PAGE_NOT_APPROVED && $takeLive) {
        parent::importArticle($article, FALSE);
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalClient::FB_INSTANT_ARTICLES_ERROR_CODE_PAGE_NOT_APPROVED constant Facebook Graph API Page Not Approved Error Code
DrupalClient::FB_INSTANT_ARTICLES_ERROR_CODE_PERMISSION constant Facebook Graph API Permision Error Code
DrupalClient::get public static function Get an Instant Articles API client instance configured with sitewide Drupal settings
DrupalClient::importArticle public function Additionally try to catch an attempted import call.