クエスト仕様

本サービスには3つのAPIが用意されています。

  • スクリーンショットの依頼
  • ステータスの取得
  • 画像の取得

スクリーンショットの依頼を出してもすぐに画像が生成される訳ではありません。リクエスト数が多いとあなたのリクエストはしばらくたってから実行され ます。画像ができたかどうかはステータスを取得するAPIを利用することによって分かります。画像の生成が完了したら生成した画像のURLにHTTPでア クセスすることによって取得できます。

スクリーンショット作成の依頼

スクリーンショット生成の依頼をおこなうためのAPIです。

リクエストURL

http://ss.ubicast.com/create

リクエストは"POST"メソッドで投げてください!

リクエストパラメータ

パラメータ 説明
txtURL(必須) string スクリーショットを作成するURL
txtSize(必須) string 横x高さで指定してください。例:340x240
txtFormat string png,jpg,gifのどれかを指定してください
txtDelay integer URLにアクセスしてからスクリーンショットを取るまでのタイムラグ(秒)を指定します。flashのLoadingメッセージが出るようなページでは長め(10秒程度)に設定してください

レスポンス

content-type:plain/textでリクエストによって生成される画像のURLのリストがプレインテキストで返ってきます。

サンプルレスポンス

http://ss.ubicast.com/PublicImage/www/ubicast/com/original.png
http://ss.ubicast.com/PublicImage/www/ubicast/com/600x400.png
http://ss.ubicast.com/PublicImage/www/opencms/jp/original.png
http://ss.ubicast.com/PublicImage/www/opencms/jp/600x400.png
http://ss.ubicast.com/PublicImage/www/yahoo/co/jp/original.png
http://ss.ubicast.com/PublicImage/www/yahoo/co/jp/600x400.png
http://ss.ubicast.com/PublicImage/www/google/co/jp/original.png
http://ss.ubicast.com/PublicImage/www/google/co/jp/600x400.png

サンプルコード(Java)

URL screenshot = new URL("http://ss.ubicast.com/create");
HttpURLConnection uc = (HttpURLConnection) screenshot.openConnection();
uc.setRequestMethod("POST");
uc.setDoOutput(true);//POST可能にする
uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

//POSTするデータ
String postStr = "txtURL="+ URLEncoder.encode("http://www.ubicast.com/","utf-8");
postStr += "&txtSize=" + URLEncoder.encode("320x240","utf-8");
postStr += "&txtFormat=" + URLEncoder.encode("png","utf-8");
postStr += "&txtDelay=" + URLEncoder.encode("5","utf-8");

int length = postStr.getBytes().length;
uc.setRequestProperty("Content-Length",Integer.toString(length));

OutputStream os = uc.getOutputStream();//POST用のOutputStreamを取得

PrintStream ps = new PrintStream(os);
ps.print(postStr);//データをPOSTする
ps.close();

ステータスの取得

スクリーンショット作成のリクエストをだしたサイトの画像が生成されたかどうかを調べるためのAPIです。

リクエストURL

http://ss.ubicast.com/status

リクエストは"POST"メソッドで投げてください!

リクエストパラメータ

パラメータ 説明
txtURL(必須) string スクリーンショット画像のURL

レスポンス

content-type:plain/textで以下のフィールドがカンマ区切りのプレインテキストで返ってきます。

パラメータ 説明
status string OK:完了/WT:作成待ち/ER:エラー発生
errorno int エラーナンバー
size int 画像ファイルのサイズ
format string 画像のフォーマット
img_url string スクリーンショット画像のURL
エラーNo.

ステータスはcontent-type:plain/textで、以下のフィールドをカンマ区切りのテキスト形式で返します。

000 ステータスがOKの時
999 ステータスがWTの時
003 不正なURLが指定された
その他 その他の理由で画像生成に失敗

サンプルレスポンス

OK,000,96x72,jpg,http://ss.ubicast.com/PublicImage/weather/yahoo/co/jp/weather/jp/16/5520.html/96x72.jpg
ER,003,,,
WT,999,320x240,jpg,http://ss.ubicast.com/PublicImage/weather/yahoo/co/jp/weather/jp/16/5520.html/320x240.jpg

サンプルコード(Java)

URL screenshot = new URL("http://ss.ubicast.com/status");
HttpURLConnection uc = (HttpURLConnection)screenshot.openConnection();
uc.setRequestMethod("POST");
uc.setUseCaches(false);
uc.setDefaultUseCaches(false);
uc.setDoOutput(true);//POST可能にする

//  POSTするデータ ex: http://www.ubicast.com/
String postStr = "txtURL="+ getUrl().toString();
OutputStream os = uc.getOutputStream();//POST用のOutputStreamを取得

PrintStream ps = new PrintStream(os);
ps.print(postStr);//データをPOSTする
ps.close();
int responseCode = uc.getResponseCode();

if( responseCode != 200 ){

return responseCode;
}

InputStream is = uc.getInputStream();//POSTした結果を取得
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String s;
while ((s = reader.readLine()) != null) {
StringTokenizer st = new StringTokenizer(s,",");
String status = st.nextToken();
String errno = st.nextToken();
String size = st.nextToken();
String format = st.nextToken();
String img_url = st.nextToken();

}
reader.close();
uc.disconnect();
return responseCode;

画像の取得

生成される画像のURLはスクリーンショット生成のリクエストの返り値として取得しているので、 この取得したURLをHTTPのGETメソッドでアクセスすれば画像ファイルを取得することが出来ます。

例:

wget http://ss.ubicast.com/PublicImage/www/ubicast/com/600x400.png