首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Facebook即时文章PHP调试行

Facebook即时文章PHP调试行
EN

Stack Overflow用户
提问于 2017-11-13 13:29:22
回答 1查看 270关注 0票数 0

我正在尝试将我的html页面转换为Facebook即时文章格式。

我一直在屏幕上

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

当我称之为“$转换器->转换字符串”或“$转换器->转换”( $header,$document );

为什么要这样?我什么都不回。

(这不是wordpress网站)

代码语言:javascript
复制
$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();
}
EN

回答 1

Stack Overflow用户

发布于 2017-11-25 18:36:25

添加以下几行:)

代码语言:javascript
复制
\Logger::configure(
[
    'rootLogger' => [
        'appenders' => ['facebook-instantarticles-traverser']
    ],
    'appenders' => [
        'facebook-instantarticles-traverser' => [
            'class' => 'LoggerAppenderConsole',
            'threshold' => 'INFO',
            'layout' => [
                'class' => 'LoggerLayoutSimple'
            ]
        ]
    ]
]);

资料来源: logger.php

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47265476

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档