旧ブログから引っ越し blogger API(google api)を使ってみました。 2006/11/25

利用しているブログサービス(blogger)がいろいろ変更があって、旧ブログ(blogger)から新ブログ(beta blogger)に移行してみました。
大きな変更は、投稿にラベルが付けれるようになりました。これは正直うれしいです。

この時点では、まだ完全にプログラマメモからのデータを移行しきれていません。


現時点で、どういうふにデータを移行したかを記しておきます。
はじめに、bloggerが全てのユーザに移行方法を提供していないので,
何か外部のツールでできないかなと考えてectoというツールを使用してみました。旧ブログからデータを取り出すことをできたのですが、どうやって新ブログにデータうつすのかで行き詰まりました。

いちいち手ではやってられないので、一括処理ができないと困ります。

次に、よくよく考えたら、blogger はAPIを公開していたはずだということで、いろいろ調べてみました。
情報源はここから、
http://code.google.com/apis/gdata/blogger.html
java用のライブラリをダウンロード

現在、bloggerはgoogleなので、google apiになっているんですね。

というわけで、旧bloogerから新bloogerに移行するためのコードをお手軽で書いてみました。

import java.io.IOException;
import java.net.URL;
import java.util.List;

import com.google.gdata.client.GoogleService;
import com.google.gdata.data.Entry;
import com.google.gdata.data.Feed;
import com.google.gdata.data.Person;
import com.google.gdata.util.ServiceException;

public class TestBlogger3 {

public static void main(String[] args) throws IOException, ServiceException {
newBlog(getFromFeed());
}

public static Feed getFromFeed() throws IOException, ServiceException {
URL feedUrl = new URL("http://www.blogger.com/feeds/xxxxblogidxxxx/posts/full");

GoogleService myService = new GoogleService("blogger", "myAppli");
myService.setUserCredentials("blogger id", "password");
Feed resultFeed = myService.getFeed(feedUrl, Feed.class);
return resultFeed;
}

public static void newBlog(Feed fromFeed) throws IOException,
ServiceException {
URL postUrl = new URL("http://www.blogger.com/feeds/blogid/posts/default");

GoogleService myService = new GoogleService("blogger",
"myAppli");
myService.setUserCredentials("google id", "password");
Person author = new Person("publisher", null, "google id");

int cnt = 0;
List list = fromFeed.getEntries();
for (Entry entry : list) {
entry.getAuthors().add(author);
Entry insertedEntry = myService.insert(postUrl, entry);
cnt += 1;
System.out.println("o_o>>" + cnt);
}

}

}

現時点で、すべての投稿を取得することができなかったので、上記のコードで完全に移行はできませんでしたが、25の投稿は移行できました。何かこの数字はAPI上の制限なのかちょっとわかりません。

ATOMとかの構造をわかると何やらhappyになれそうな感じがしました。
いまさらながら、APIを公開しているのはよいですね、web2.0って便利ですね。

: