DrupalClient.php in Facebook Instant Articles 7
File
modules/fb_instant_articles_api/src/DrupalClient.php
View source
<?php
namespace Drupal\fb_instant_articles_api;
use Facebook\InstantArticles\Client\Client;
use Facebook\Exceptions\FacebookResponseException;
class DrupalClient extends Client {
const FB_INSTANT_ARTICLES_ERROR_CODE_PERMISSION = 200;
const FB_INSTANT_ARTICLES_ERROR_CODE_PAGE_NOT_APPROVED = 1888205;
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);
}
public function importArticle($article, $takeLive = FALSE) {
try {
parent::importArticle($article, $takeLive);
} catch (FacebookResponseException $e) {
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);
}
}
}
}
Classes
Name |
Description |
DrupalClient |
Encapsulates any Drupal-specific logic when using the Client. |