Facebook Instant Articles PHP SDK 调试行

Posted

技术标签:

【中文标题】Facebook Instant Articles PHP SDK 调试行【英文标题】:Facebook Instant Articles PHP SDK debug line 【发布时间】:2017-11-13 13:29:22 【问题描述】:

我正在尝试将我的 html 页面转换为 Facebook Instant Articles 格式。

我一直在屏幕上

“调试-============================调试-”

当我调用“$transformer->transformString”或“ $transformer->transform($header, $document);"

为什么?我没有回应任何东西。

(这不是 wordpress 网站)

$header =
    Header::create()
      ->withPublishTime(
        Time::create( Time::PUBLISHED )->withDatetime(
            \DateTime::createFromFormat(
              'j-M-Y G:i:s',
              date('j-M-Y G:i:s', strtotime($published_date))
            ))
      )
      ->withModifyTime(
        Time::create( Time::MODIFIED )->withDatetime(
            \DateTime::createFromFormat(
              'j-M-Y G:i:s',
              date('j-M-Y G:i:s', strtotime($last_modified_date))
            ))
      );
// Loads the rules configuration file

$rules_file_content = file_get_contents("rules-configuration.json", true); 
// Load html content from a file. 
//$content = file_get_contents("sample-html.html", true);
$content = get_the_content();

// Create a transformer object and load the rules
$transformer = new Transformer();
$transformer->loadRules($rules_file_content);
$document = new DOMDocument();
libxml_use_internal_errors(true);
$document->loadHTML( '<?xml encoding="' . $charset . '" ?><h1>' . $title . '</h1>' );
libxml_use_internal_errors(false);

$transformer->transform( $header, $document );

if($subtitle) 
  $header->withSubTitle ($subtitle);


if ( $kicker ) 
  $header->withKicker( $kicker );

    define( 'IA_PLUGIN_VERSION', '4.0.5' );

$instant_article =
      InstantArticle::create()
        ->withCanonicalUrl( $cannonical_link )
        ->withHeader( $header )
        ->addMetaProperty( 'op:generator:application', 'facebook-instant-articles' )
        ->addMetaProperty( 'op:generator:application:version', IA_PLUGIN_VERSION );
$instant_article->withStyle( 'default' );
$transformer->transformString( $instant_article, $content, $charset );
// Instantiate an API client
$client = Client::create(
  $APP_ID,
  $APP_SECRET,
  $ACCESS_TOKEN,
  $PAGE_ID,
  $is_development 
);
// Import the article
try 
    $client->importArticle($instant_article, $is_published);
 catch (Exception $e) 
    echo 'Could not import the article: '.$e->getMessage();

【问题讨论】:

github.com/facebook/facebook-instant-articles-sdk-php/… @CBroe 我怎样才能绕过它? 是否处于开发模式? @LeopoldSpanovic 我该如何检查? 【参考方案1】:

添加这些行:)

\Logger::configure(
[
    'rootLogger' => [
        'appenders' => ['facebook-instantarticles-traverser']
    ],
    'appenders' => [
        'facebook-instantarticles-traverser' => [
            'class' => 'LoggerAppenderConsole',
            'threshold' => 'INFO',
            'layout' => [
                'class' => 'LoggerLayoutSimple'
            ]
        ]
    ]
]);

来源: https://github.com/facebook/facebook-instant-articles-sdk-extensions-in-php/blob/master/examples/quiet_logger.php

【讨论】:

以上是关于Facebook Instant Articles PHP SDK 调试行的主要内容,如果未能解决你的问题,请参考以下文章

在Vue项目中使用Facebook Instant Games CDN - Webpack

如何访问和传递参数到 Android Instant App 的模块

如何访问和传递参数到 Android Instant App 的模块

instant的短语都有哪些_instant的知识

instant的近义词辨析

Java8 Instant 时间戳