GAE/Jで「適当なフィードをを読み込み表示する」ってのをやろうとして、
まずはURLフェッチの低レベルAPIを試してみました。
http://code.google.com/intl/ja/appengine/docs/java/javadoc/com/google/appengine/api/urlfetch/package-summary.html
ソースはこんな感じになります。
--------【Java】--------
import com.google.appengine.api.urlfetch.HTTPMethod;
import com.google.appengine.api.urlfetch.HTTPRequest;
import com.google.appengine.api.urlfetch.HTTPResponse;
import com.google.appengine.api.urlfetch.URLFetchService;
import com.google.appengine.api.urlfetch.URLFetchServiceFactory;
import static com.google.appengine.api.urlfetch.FetchOptions.Builder.disallowTruncate;
...
URLFetchService fetchService = URLFetchServiceFactory.getURLFetchService();
HTTPRequest httpRequest = new HTTPRequest(
new URL("http://feeds.feedburner.com/suz-lab-blog"),
HTTPMethod.GET,
disallowTruncate().followRedirects()
);
HTTPResponse httpResponse = fetchService.fetch(httpRequest);
...
--------
上記コードで"httpResponse"から
指定したURLのヘッダやコンテンツを取得することができます。
http://code.google.com/intl/ja/appengine/docs/java/javadoc/com/google/appengine/api/urlfetch/HTTPResponse.html
HTTPRequestの第三引数のオプションは下記を参考に。
http://code.google.com/intl/ja/appengine/docs/java/javadoc/com/google/appengine/api/urlfetch/FetchOptions.html
次はフィードの処理です。
--------
http://www.suz-lab.com

0 コメント:
コメントを投稿