PHP:
-
<?php
-
require_once('Zend/Gdata.php');
-
require_once('Zend/Gdata/Query.php');
-
require_once('Zend/Gdata/ClientLogin.php');
-
-
//向 Blogger发送文章,可自定义Tag
-
class Blogger{
-
private $gdClient;
-
private $blogID;
-
-
public function __construct($mail, $password, $blogID){
-
$service = 'blogger';
-
$client = Zend_Gdata_ClientLogin::getHttpClient($mail, $password, $service);
-
$this->gdClient = new Zend_Gdata($client);
-
$this->blogID = $blogID;
-
}
-
-
public function printAllBlogs(){
-
$query = new Zend_Gdata_Query('https://www.blogger.com/feeds/default/blogs');
-
$feed = $this->gdClient->getFeed($query);
-
$this->printFeed($feed);
-
}
-
-
public function printFeed($feed){
-
$i = 0;
-
foreach($feed->entries as $entry) {
-
$i++;
-
}
-
}
-
-
public function createPublishedPost($title='Hello, world!', $content='I am blogging on the internet.', $category= '', $publish){
-
$uri = 'https://www.blogger.com/feeds/' . $this->blogID . '/posts/default';
-
$entry = $this->gdClient->newEntry();
-
$entry->title = $this->gdClient->newTitle($title);
-
$entry->content = $this->gdClient->newContent($content);
-
$entry->published = $this->gdClient->newPublished($publish);
-
}else{
-
$categorys[] = $category;
-
}
-
foreach ($categorys as $key =>$value){
-
$labels[] = new Zend_Gdata_App_Extension_Category($value, 'http://www.blogger.com/atom/ns#');
-
}
-
-
$entry->setCategory($labels);
-
-
$entry->content->setType('text');
-
-
$createdPost = $this->gdClient->insertEntry($entry, $uri);
-
$newPostID = $idText[2];
-
-
return $newPostID;
-
}
-
-
}