google calendar api delphi

2019-08-06 19:51发布

问题:

I have been programming in DELPHI, work with google calendar and I want to delete an event but I have to go bug.

procedure TForm1.Button1Click (Sender: TObject);    
var    
 url: string;    
 slParam: TStringList;    
begin    
  test: ='';    
  IdHTTP2.Request.CustomHeaders.Clear;    
  IdHTTP2.Request.Connection: = 'Keep-Alive';    
  IdHTTP2.Request.ContentType: = 'application / atom xml';    
  IdHTTP2.Request.CustomHeaders.Values ['GData-Version']: = '2';    
  IdHTTP2.Request.CustomHeaders.Values ['Authorization']: = 'GoogleLogin auth =' auth;    
  IdHTTP2.HandleRedirects: = true;    
  url: =  http://www.google.com/calendar/feeds/u0qtqn2cke6pjppu1vgj5pj8js  %40group.calendar.google.com/private/full    
  slParam: = TStringList.Create;    
  slParam.LoadFromFile ('udalit.xml');    
  try    
    test: = IdHTTP2.Post (url, slParam);    
    memo1.Lines.Add (test);    
  except    
 on E: EIdHTTPProtocolException do    
   ShowMessage (E.ErrorMessage);    
  end;    
  FreeAndNil (slParam);    
end;

Here is my xml file I'm trying to send

<?xml version="1.0" encoding="UTF-8" ?>   
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns:batch="http://schemas.google.com/gdata/batch" xmlns:gCal="http://schemas.google.com/gCal/2005" xmlns:gd="http://schemas.google.com/g/2005">  
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event" />   
<entry gd:etag=""FEUDQAdBfSp7JGA6WhJV"">  
<batch:id>Delete itemD</batch:id>   
<batch:operation type="delete" />   
<id>http://www.google.com/calendar/feeds/u0qtqn2cke6pjppu1vgj5pj8js%40group.calendar.google.com/private/full/ihpe431ebmk9pa39dskjilnsko</id>   
</entry>  
</feed>

will generate an error when sending

[Line 1, Column 227] Invalid root element, expected (http://www.w3.org/2005/Atom:entry), got (http://www.w3.org/2005/Atom:feed)

回答1:

It seems that you don't need to send a file to delete an event. According to the Calendar API, you just need to call the URI.

To delete a calendar resource, send a DELETE request to a resource ID's feed URL. Include the Authorization header as described in Authenticating.

DELETE https://apps-apis.google.com/a/feeds/calendar/resource/2.0/{domain name}/{resourceId}

A successful response returns an HTTP 200 status code from the Google Data API status codes. The XML body of a successful response to a DELETE request is empty.