TGoogleCalender =
record
etag,id,summary,description:
string;
end;
TGoogleCalenderArray =
array of TGoogleCalender;
var
calenderList : TGoogleCalenderArray;
const
apikey = '
AIXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXE';
procedure TFormMain.Button1Click(Sender: TObject);
const
baseURLlogin :
string = '
https://www.google.com/accounts/ClientLogin';
baseURLcalendars :
string = '
https://www.googleapis.com/calendar/v3/users/me/calendarList';
var
stringStream: TStringStream;
slPost, slReply: TStringList;
sPostResult:
string;
sGetResult:
string;
authCode :
string;
item : integer;
I: Integer;
begin
slPost := TStringList.Create;
slReply := TStringList.Create;
try
slPost.LineBreak := '
&';
slPost.Values['
Email'] := '
XXXXXXX@gmail.com';
slPost.Values['
Passwd'] := '
XXXXX';
slPost.Values['
service'] := '
cl';
slPost.Values['
source'] := '
Test';
stringStream := TStringStream.Create(slPost.Text);
try
IdHTTP1.Request.ContentType := '
application/x-www-form-urlencoded';
sPostResult := IdHTTP1.Post(baseURLlogin, stringStream);
slReply.LineBreak:=#10;
slReply.Text:=sPostResult;
authCode:=slReply.Values['
auth'];
slReply.LineBreak:=#13#10;
if pos('
200 OK',IdHTTP1.ResponseText)>0
then
begin
IdHTTP1.Request.CustomHeaders.FoldLines:=false;
IdHTTP1.Request.CustomHeaders.Clear;
IdHTTP1.Request.CustomHeaders.Values['
Authorization']:='
GoogleLogin auth=' + authCode;
IdHTTP1.Request.ContentType := '
application/atom+xml';
sGetResult :=IdHTTP1.Get(baseURLcalendars+'
?minAccessRole=writer&key='+apikey);
calenderList := getCalenders(sGetResult);
for I := 0
to length(calenderList) - 1
do
begin
ComboBox1.Items.Add(calenderlist[I].summary);
end;
ComboBox1.ItemIndex := 2;
end;
finally
stringStream.Free;
end;
finally
slPost.Free;
slReply.Free;
end;
end;