dpea85385 2017-11-13 13:29
浏览 24

Facebook即时文章PHP SDK调试行

I'm trying to transform my html page to Facebook Instant Articles format.

I keep getting on the screen

"DEBUG - =========================== DEBUG -"

When Im calling "$transformer->transformString" or " $transformer->transform( $header, $document );"

Why that? I don't echo anything.

(This isn't wordpress site)

$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();
}
  • 写回答

1条回答 默认 最新

  • dongwen5870 2017-11-25 18:36
    关注

    Add these lines :)

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

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

    评论

报告相同问题?

悬赏问题

  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭