簡體   English   中英

使用Delphi在Google日歷中創建事件-錯誤401

[英]Create event in Google Calendar with Delphi - Error 401

我的程序必須連接到Google日歷並創建一個事件,但是我收到一條錯誤消息,內容為“令牌無效-AuthSub令牌的作用域錯誤”

網址為http://www.google.com/calendar/feeds/default/owncalendars/full

這是我的代碼:

Begin
  createXML := '<?xml version=''1.0'' encoding=''UTF-8''?>'#13#10 +
                  '<entry xmlns=''http://www.w3.org/2005/Atom'''#13#10 +
                  'xmlns:gd=''http://schemas.google.com/g/2005''>'#13#10 +
                  '<category scheme=''http://schemas.google.com/g/2005#kind'''#13#10 +
                  'term=''http://schemas.google.com/g/2005#event''></category>'#13#10 +
                  '<title type=''text''>' + title + '</title>'#13#10 +
                  '<content type=''text''>' + content + '</content>'#13#10 +
                  '<gd:transparency'#13#10 +
                  'value=''http://schemas.google.com/g/2005#event.opaque''>'#13#10 +
                  '</gd:transparency>'#13#10 +
                  '<gd:eventStatus'#13#10 +
                  'value=''http://schemas.google.com/g/2005#event.confirmed''>'#13#10 +
                  '</gd:eventStatus>'#13#10 +
                  '<gd:where valueString=''' + location + '''></gd:where>'#13#10 +
                  '<gd:when startTime=''' + EventStartTime + ''''#13#10 +
                  'endTime=''' + EventEndTime + '''></gd:when>'#13#10 +
                  '</entry>';

  HTTP:=THTTPSend.Create;
  url:=Edit3.Text;
  WriteStrToStream(HTTP.Document,EncodeURL(createXML));
  HTTP.Headers.Add('Authorization: OAuth '+OAuth.Access_token);
  HTTP.Headers.Add('GData-Version: 2');
  HTTP.MimeType:=('application/atom+xml');
  if HTTP.HTTPMethod('POST',url) then
  XML:=HTTP.Document;
  Memo2.Lines.LoadFromStream(XML);
End;

這是我的OAuth連接代碼...

 Const
    client_id=%s&client_secret=%s&code=%s&redirect_uri=%s&grant_type=authorization_‌​‌​code'; 

.....

        procedure TForm2.Button4Click(Sender: TObject); var HTTP:THTTPSend; 
        begin HTTP:=THTTPSend.Create; 
        try 
        HTTP.Headers.Add('Authorization: OAuth '+OAuth.Access_token); 
        HTTP.Headers.Add('GData-Version: 2'); 
        if       HTTP.HTTPMethod('GET','google.com:443/calendar/feeds/default/allcalendars/full') then 
        XML:=HTTP.Document; 
        End;

非常感謝您的寶貴時間。

用戶:Google翻譯

在這里,您可以閱讀協議,包括所需的授權標頭。 即使添加了代碼,也仍然不清楚OAuth對象是如何構建的。

但是,不建議您繼續使用GData API,因為它已被棄用。 考慮將基於JSON的v3版本與新的身份驗證方法一起使用。 API規范和用法也是新的,因此您需要花費一些時間。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM