この記事は2年以上前に書かれたものです。
情報が古い可能性があります。
情報が古い可能性があります。
HTMLファイルの作成と設置
MTがインストールされている同じドメインのサーバにHTMLファイルを作成します。
今回、http://example.com/dataapi/index.html にファイルを作成しました。
http://example.com/ にMovable Type6がインストールされていることを前提としています。ドメイン部分はご自身の環境に置き換えてください。
index.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8" />
<title>DataAPIのテスト</title>
<link rel="stylesheet" href="css/style.css" />
<!-- jQueryとDataAPIを使用するために用意されているJavaScript SDKを読み込みます -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://example.com/mt-static/data-api/v1/js/mt-data-api.min.js"></script>
</head>
<body>
<script>
// DataAPIを使用する準備を行います
// clientIdには英数字、アンダースコア、ハイフンを組み合わせた任意の文字列を指定します
// baseUrlにはMTをインストールしているディレクトリのmt-data-api.cgiまでのパスを指定します
var api = new MT.DataAPI({
clientId: 'example',
baseUrl: 'http://example.com/mt-data-api.cgi',
});
// ブログID = 1の記事一覧を取得し、id="result" の要素にjQueryを使用してappendします
var siteId = 1;
api.listEntries( siteId, function( response ) {
if ( response.error ) {
return;
}
for ( i=0; i< response.items.length; i++ ) {
jQuery( '#result' ).append( $( '<li>' ).append( response.items[i].title ) );
}
});
</script>
<h1>DataAPIのテスト</h1>
<!-- この要素に取得結果を表示します -->
<div id="result"></div>
</body>
</html>
設置したHTMLのURLにアクセス
http://example.com/dataapi/index.html にブラウザからアクセスします。

記事の一覧が表示されました:)
以下、title以外に取得できる項目のデータのサンプルです。
{
"author" : {
"id" : 1,
"displayName" : "Yuji Takayama",
"userpicUrl" : "http://host.domain/mt-static/support/assets_c/userpics/userpic-1-32x32.png"
},
"blog" : {
"id" : 1
},
"categories" : [
"primary cat",
"secondary/sub",
"[include/slash]"
],
"id" : 1,
"class" : "entry",
"status" : "Publish",
"allowComments" : true,
"allowTrackbacks" : true,
"title" : "This is an entry.",
"body" : "Foo bar",
"more" : "blah blah blah",
"excerpt" : "Foo",
"keywords" : "some keywords",
"basename" : "this_is_an_entry",
"permalink" : "http://host.domain/blog/2012/01/entry.html",
"pingsSentUrl" : [
"http://example.com/blog/foo.html"
],
"date" : "2013-01-11T12:48:12+09:00",
"createdDate" : "2013-01-11T12:48:12+09:00",
"modifiedDate" : "2013-01-11T12:48:12+09:00",
"commentCount" : 2,
"trackbackCount" : 1,
"comments" : [
{
"status" : "Approved",
"parent" : 2,
"link" : "http://host.domain/blog/2012/01/entry.html#comment-1",
"id" : 1,
"entry" : {
"id" : 1
},
"date" : "2013-01-11T12:48:12+09:00",
"customFields" : {
"items" : [
{
"value" : "Test data",
"basename" : "cf_fields_1"
},
{
"value" : "Test data 2",
"basename" : "cf_field_2"
}
]
},
"body" : "This is a test comment.\nHe he he",
"blog" : {
"id" : 1
},
"author" : {
"userpicUrl" : "http://host.domain/mt-static/support/assets_c/userpics/userpic-1-32x32.png",
"displayName" : "Yuji Takayama",
"id" : 1
}
}
],
"trackbacks" : [
{
"blog" : {
"id" : 1
},
"entry" : {
"id" : 1
},
"id" : 1,
"date" : "2013-01-11T12:48:12+09:00",
"title" : "Trackback entry",
"excerpt" : "blah blah blah",
"blogName" : "Sent from",
"url" : "http://example.com/blog/trackback.html",
"ip" : "10.11.12.13"
}
],
"assets" : [
{
"id" : 1,
"label" : "Sample Image",
"description" : "My family portrait.",
"mimeType" : "",
"tags" : [
"photo",
"portrait"
],
"url" : "http://example.com/images/foo.jpg"
}
],
"updatable": true,
"customFields" : [
{
"basename" : "cf_flag",
"value" : "any"
}
],
"tags" : [
"news",
"keyword"
]
}
via : Data api entries list · movabletype/Documentation Wiki · GitHub