You are here

public function DrupalClient::importArticle in Facebook Instant Articles 3.x

Same name and namespace in other branches
  1. 8.2 src/DrupalClient.php \Drupal\fb_instant_articles\DrupalClient::importArticle()

Additionally try to catch an attempted import call that failed from an authorization exception. In such a case, try again as unpublished if the situation allows.

1 call to DrupalClient::importArticle()
DrupalClient::importEntity in src/DrupalClient.php
Import a content entity into Instant Articles.

File

src/DrupalClient.php, line 91

Class

DrupalClient
Encapsulate Drupal-specific logic for FBIA Client.

Namespace

Drupal\fb_instant_articles

Code

public function importArticle($article, $published = FALSE, $forceRescrape = FALSE, $formatOutput = FALSE) {
  try {
    parent::importArticle($article, $published, $forceRescrape, $formatOutput);
  } 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 && $published) {
      parent::importArticle($article, FALSE);
    }
  }
}