BloggerAPI:用PHP发布一篇带有标签的文章
通过使用BloggerAPI,我想用PHP发布一篇带有多个标签的文章。目前,文章发布成功,但没有添加标签。这是我的代码:BloggerAPI:用PHP发布一篇带有标签的文章,php,blogger,Php,Blogger,通过使用BloggerAPI,我想用PHP发布一篇带有多个标签的文章。目前,文章发布成功,但没有添加标签。这是我的代码: $blogId = "myBlogId"; $data = array("kind" => "blogger#post", "blog" => array("id" => $blogId), "title" => "test", "content" => "content", "labels" => ["t1", "t2"]);
$blogId = "myBlogId";
$data = array("kind" => "blogger#post", "blog" => array("id" => $blogId), "title" => "test", "content" => "content", "labels" => ["t1", "t2"]);
$data = json_encode($data);
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/blogger/v3/blogs/'.$blogId.'/posts?key='.$myApiKey);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json', 'Authorization: OAuth '.$accessToken));
curl_setopt($curlObj, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($curlObj);
curl_close($curlObj);
回复不会返回错误,帖子在我的博客中可见,但没有标签。错误在哪里?我可以使用以下代码插入帖子。 首先获取访问令牌,设置访问令牌,然后将经过身份验证的
$client
传递给Google\u Service\u 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;
}
我可以使用以下代码插入帖子。 首先获取访问令牌,设置访问令牌,然后将经过身份验证的
$client
传递给Google\u Service\u 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;
}