AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Object-Pascal / Delphi-Language Delphi Http.Post für die Google Calendar API ???
Thema durchsuchen
Ansicht
Themen-Optionen

Http.Post für die Google Calendar API ???

Ein Thema von bodycounter · begonnen am 21. Sep 2012 · letzter Beitrag vom 25. Sep 2012
 
bodycounter

Registriert seit: 13. Jul 2004
12 Beiträge
 
#1

Http.Post für die Google Calendar API ???

  Alt 21. Sep 2012, 19:36
Delphi-Version: 2009
Hallo.

Ich versuche die ganze Zeit ein HTTP POST für die Google Calendar API zu basteln.
Aber es will nicht funktionieren. Ich kann mich einloggen und mit HTTP GET die Kalender Liste bekommen.
Und zwar so:

Delphi-Quellcode:
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;
Danach versuche ich einen neuen Eintrag in einem Kalendar anzulegen. Aber das klappt nicht. Kann mir einer helfen?
DANKE

Delphi-Quellcode:
procedure TFormMain.Button2Click(Sender: TObject);
const
    baseURLevent : string = 'https://www.googleapis.com/calendar/v3/calendars/CID/events?key=APIKEY' ; // replace CID and APIKEY
var
    slPost : TStringList;
    stringStream: TStringStream;
    postResult : string;
    URLevent : string;
begin
    slPost := TStringList.Create;
    slPost.LineBreak := '';
    slPost.Add('{');
    slPost.Add('"end": {');
    slPost.Add('"dateTime": "'+formatdatetime('yyyy-mm-dd"T"hh:mm:ss',now)+'",');
    slPost.Add('"timeZone": "Europe/Berlin"');
    slPost.Add('},');
    slPost.Add('"start": {');
    slPost.Add('"dateTime": "'+formatdatetime('yyyy-mm-dd"T"hh:mm:ss',now+5)+'",');
    slPost.Add('"timeZone": "Europe/Berlin"');
    slPost.Add('},');
    slPost.Add('"description": "Hier ist die Beschreibung",');
    slPost.Add('"summary": "Das hier ist der Title",');
    slPost.Add('"colorId": "6",');
    slPost.Add('"reminders": {');
    slPost.Add('"overrides": [');
    slPost.Add('{');
    slPost.Add('"method": "popup",');
    slPost.Add('"minutes": 1440');
    slPost.Add('},');
    slPost.Add('{');
    slPost.Add('"method": "email",');
    slPost.Add('"minutes": 720');
    slPost.Add('}');
    slPost.Add('],');
    slPost.Add('"useDefault": false');
    slPost.Add('}');
    slPost.Add('}');

    stringStream := TStringStream.Create(slPost.Text);
    IdHTTP1.Request.ContentType := 'application/json';

    URLevent := baseURLevent;
    URLevent := StringReplace(URLevent,'CID',calenderList[ComboBox1.ItemIndex].id,[]);
    URLevent := StringReplace(URLevent,'APIKEY',apikey,[]);

    postResult := IdHTTP1.POST(URLevent, stringStream);
    // Hier kommt dann der Fehler
end;
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:53 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz