Help us understand the problem. What is going on with this article?

cybozu soap APIを叩いて、自分の本日のスケジュールを取得するサンプル(PHP)

More than 1 year has passed since last update.
sample.php
$username='{cybozuのユーザー名}';
$password='{cybozuのパスワード}';

$today = date('Y-m-d');
$todayFrom = $today.'T00:00:00Z';
$todayTo   = $today.'T23:59:59Z';

// 送信先
$url='https://{サブドメイン名}.cybozu.com/g/cbpapi/schedule/api.csp';

// ヘッダ
$headers = [
    'Content-Type: application/soap+xml; charset=UTF-8',
    'action="ScheduleGetEvents"',
];

// リクエスト内容
$postdata =<<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
  <soap:Header>
    <Action>ScheduleGetEvents</Action>
    <Security>
      <UsernameToken>
        <Username>{$username}</Username>
        <Password>{$password}</Password>
      </UsernameToken>
    </Security>
    <Timestamp>
      <Created>2013-06-01T00:00:00Z</Created>
      <Expires>2037-12-31T00:00:00Z</Expires>
    </Timestamp>
  </soap:Header>
  <soap:Body>
    <ScheduleGetEvents>
      <parameters start="{$todayFrom}" end="{$todayTo}">
      </parameters>
    </ScheduleGetEvents>
  </soap:Body>
</soap:Envelope>
EOF;


$curl = curl_init( $url );
curl_setopt( $curl, CURLOPT_POST, TRUE );
curl_setopt( $curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true); // curl_execの結果を文字列で返す
$contents = curl_exec( $curl );
curl_close($curl);


$reader = new XMLReader();
$reader->XML($contents);

// 結果出力
// あとはDOM操作なので、適当にお好みの形に整形してください。
$scheduleArr = [];
while($reader->read()) {

    if( $reader->nodeType == XMLReader::ELEMENT &&
            $reader->name == 'schedule_event' &&
            $reader->getAttribute("event_type") != "banner")
    {
        $scheduleItem = [];
        $doc = new DOMDocument('1.0', 'UTF-8');
        $scheduleEvent = simplexml_import_dom($doc->importNode($reader->expand(),true));
        //echo print_r($scheduleEvent,1);
        if( $scheduleEvent['public_type'] == "public" ) {
            $scheduleItem['detail'] = (string)($scheduleEvent['detail']);
        }
        else {
            $scheduleItem['detail'] = "予定あり";
        }

        if( $scheduleEvent['event_type'] == "repeat" ) {
            $scheduleItem['start'] = (string)($scheduleEvent->repeat_info->condition['start_time']);
            $scheduleItem['end']   = (string)($scheduleEvent->repeat_info->condition['end_time']);
        }
        else if( $scheduleEvent['event_type'] == "normal" ) {
            $scheduleItem['start'] = strftime( '%T', strtotime( $scheduleEvent->when->datetime['start'] ) );
            $scheduleItem['end']   = strftime( '%T', strtotime( $scheduleEvent->when->datetime['end'] ) );
        }
        $scheduleArr[] = $scheduleItem;
    }
}
$reader->close();

/**
scheduleArrが
[
    [
        "detail" => "予定タイトル",
        "start"  => "開始時間",
        "end"  => "終了時間",
    ]
]
みたいな形になります。
*/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした