2009年7月11日土曜日

phpで指定したgoogleカレンダーに権限を追加する。

Zend_Gdata_Calendar クラスを利用してxmlを送る。
・post() を使ってxmlを特定のurlに送る。
・レスポンスはZend_Http_Responseクラスで受け取る。
・今回は、getStatusを利用してレスポンスコードを受け取りそれで完了したことを確認する。

□権限の種類
owner 変更および共有の管理権限
editor 予定の変更権限
read 閲覧権限(すべての予定の詳細)
freebusy 予定の時間枠のみ表示(詳細は非表示)


require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
// ClientAuth 認証用のパラメータ
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$user = "googleのアカウント";
$pass = "googleのパスワード";
// 認証済みの HTTP クライアントを作成します
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);

$calendarid = "グーグルカレンダーのID";

addACL($client,'追加したい人のgoogleのアカウント','権限',$calendarid);

function addACL($client,$user,$role, $calendar_id){
$xml = "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gAcl='http://schemas.google.com/acl/2007'>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/acl/2007#accessRule'/>
<gAcl:scope type='user' value='[USER]'></gAcl:scope>
<gAcl:role value='http://schemas.google.com/gCal/2005#[ROLE]'></gAcl:role>
</entry>";

$gdataCal = new Zend_Gdata_Calendar($client);


$uri = 'http://www.google.com/calendar/feeds/'.$calendar_id.'/acl/full';
$xml = str_replace('[USER]', $user, $xml);
$xml = str_replace('[ROLE]', $role, $xml);

$response = $gdataCal->post($xml, $uri);
if($response->getStatus() == 200 or $response->getStatus() == 201){
print "OK";
}
}


追記
・googleの権限を追加するためのアドレス(googleアカウント)、googleのカレンダーのアドレスとでは@の処理の仕方が違う。httprequestのurlに指定するのでgoogleカレンダーのアドレスは%40に変換する必要がある。

0 件のコメント:

コメントを投稿