Created
July 17, 2014 04:47
-
-
Save fddcddhdd/7bf65db575ce9e347c80 to your computer and use it in GitHub Desktop.
サイボウズのkinton REST APIを使って、PHPでデータ取得するサンプルコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 自分のkintoneの設定 | |
define("API_TOKEN", ""); | |
define("SUB_DOMAIN", ""); | |
define("APP_NO", "1"); | |
//サーバ送信するHTTPヘッダを設定 | |
$options = array( | |
'http'=>array( | |
'method'=>'GET', | |
'header'=> "X-Cybozu-API-Token:". API_TOKEN ."\r\n" | |
) | |
); | |
//コンテキストを生成 | |
$context = stream_context_create( $options ); | |
// サーバに接続してデータを貰う | |
$contents = file_get_contents( 'https://'. SUB_DOMAIN .'.cybozu.com/k/v1/records.json?app='. APP_NO , FALSE, $context ); | |
//var_dump($http_response_header); //ヘッダ表示 | |
//JSON形式からArrayに変換 | |
$data = json_decode($contents, true); | |
//表示は単純なテーブルで | |
$str = "<table border='1'>"; | |
$str .= "<tr>"; | |
$str .= "<th>レコード番号</th>"; | |
$str .= "<th>作成日時</th>"; | |
$str .= "<th>作成者</th>"; | |
$str .= "<th>更新日時</th>"; | |
$str .= "<th>更新者</th>"; | |
$str .= "<th>文字列__1行_</th>"; | |
$str .= "</tr>"; | |
for($i=0; $i<count($data['records']); $i++){ | |
$str .= "<tr>"; | |
$str .= sprintf("<td>%s</td>", $data['records'][$i]['レコード番号']['value']); | |
$str .= sprintf("<td>%s</td>", $data['records'][$i]['作成日時']['value']); | |
$str .= sprintf("<td>%s</td>", $data['records'][$i]['作成者']['value']['name']); | |
$str .= sprintf("<td>%s</td>", $data['records'][$i]['更新日時']['value']); | |
$str .= sprintf("<td>%s</td>", $data['records'][$i]['更新者']['value']['name']); | |
$str .= sprintf("<td>%s</td>", $data['records'][$i]['文字列__1行_']['value']); | |
$str .= "</tr>"; | |
} | |
$str .= "</table>"; | |
//画面に出力 | |
echo $str; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment