2012-02-16 183 views
1

我一直在DELPHI编程,使用谷歌日历,我想删除一个事件,但我必须去错误。谷歌日历api delphi

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; 

这里是我的xml文件,我想送

<?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> 

将产生一个错误发送

[1号线,列227]无效的根元素时,预计 (http://www.w3.org/2005/Atom:entry),得到 (http://www.w3.org/2005/Atom:feed)

+1

HTTP规范禁止您在Content-Type标头中使用空格。您还应该尝试正确拼写:'application/atom + xml'具有必需的加号。你的代码中也有语法错误。请复制并粘贴真实的代码,否则人们不会相信您报告的问题是真实的。 – 2012-02-16 16:48:29

回答

4

看来,您不需要发送文件来删除事件。根据Calendar API,你只需要调用URI。

要删除日历资源,请向资源ID的供稿网址发送DELETE请求。按照身份验证中所述包含授权标头。

https://apps-apis.google.com/a/feeds/calendar/resource/2.0/ DELETE {域名}/{RESOURCEID}

成功的响应返回来自谷歌数据API状态码的HTTP 200状态代码。成功响应DELETE请求的XML正文为空。