拙著「FXはチャートで勝つ!」が発売されました。
FX(外国為替証拠金取引)でのチャートの読み方を解説しています。
自由国民社刊で、定価1,728円(消費税込み)です。
Data API Library for Android(その7・オブジェクト作成系メソッド)
Data API Library for Androidの解説その7です。
今回はオブジェクトを作成するメソッドの使い方を解説します。
1.メソッドの一覧
オブジェクトを作成するメソッドの名前は、一部を除き「create○○○」のような名前になっています。
引数として、サイトのID/オブジェクトのIDと、作成するオブジェクトを取ります。
各メソッドで必要なIDは、以下の表のとおりです。
また、オブジェクトはJSONObject型の変数で表します。
| メソッド名 | 必要なID |
|---|---|
| createEntry | site_id |
| createComment | site_id, entry_id |
| createReplyComment | site_id, entry_id, comment_id |
| createCategory | site_id |
| createFolder | site_id |
| createEntry | site_id |
| createPage | site_id |
| createCommentForPage | site_id, page_id |
| createReplyCommentForPage | site_id, page_id, comment_id |
| createRole | なし |
| createLog | site_id |
| createTemplate | site_id |
| createTemplatemap | site_id, template_id |
| createWidgetset | site_id |
| createWidget | site_id |
| createUser | なし |
| createField | site_id |
| createFormattedText | site_id |
| insertNewBlog | site_id |
| insertNewWebsite | なし |
2.事例
以下のような状況だとします。
- サイトIDが変数siteIDに入っています。
- 記事のタイトルと本文が、変数title/bodyに入っています。
この状況で記事を作成するには、以下のようなコードを実行します。
JSONObject entry = new JSONObject();
try {
entry.put("title", title);
entry.put("body", body);
} catch (JSONException e) {
e.printStackTrace();
}
DataAPI.send("createEntry", siteID, entry, new DataAPIListener() {
@Override
public void onResponse(JSONObject resp) {
記事作成完了時の処理
}
@Override
public void onError(VolleyError error) {
記事作成に失敗したときの処理
}
});
