Blogger API:在PHP中发布带有标签的文章

时间:2015-08-28 09:34:25

标签: php blogger

通过使用Blogger API,我想在PHP中发布一篇包含多个标签的文章。目前,文章已成功发布,但未添加标签。这是我的代码:

select * from tableA;                                                           
OK
1440753288123
Time taken: 0.071 seconds, Fetched: 1 row(s)
hive> select toDate(timestamp) from tableA;
OK
201508240144448:123
Time taken: 0.08 seconds, Fetched: 1 row(s)

响应没有返回错误,帖子在我的Blogger中可见但没有标签。错误在哪里?

1 个答案:

答案 0 :(得分:0)

我可以使用以下代码插入帖子。 首先获取访问令牌,设置访问令牌,然后将经过身份验证的$client传递给the Google_Service_Blogger()类。

public function insert_post( $blogId, $postBody ) {
    $Blogger = new Google_Service_Blogger( $this->client );
    $NewPost = new Google_Service_Blogger_Post();

    // set title
    if ( isset( $postBody['title'] ) ) {
        $NewPost->setTitle( $postBody['title'] );
    }

    // set content
    if ( isset( $postBody['content'] ) ) {
        $NewPost->setContent($postBody['content'] );
    }

    // set labels
    if ( isset( $postBody['labels'] ) ) {
        $NewPost->setLabels( $postBody['labels'] );
    }


    $response = [];
    try {
        $response['post'] = $Blogger->posts->insert( $blogId, $NewPost );
    } catch ( Exception $e ) {
        $response['error'] = $e;
    }

    return $response;
}