【发布时间】:2014-06-14 17:31:50
【问题描述】:
我的程序必须连接到 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;
非常感谢您的宝贵时间。
用户:谷歌翻译
【问题讨论】:
-
如果您改为添加与 OAuth.Access_token 相关的代码会很有用。
-
@AMS 添加 Oauth Connect 的代码,完成。
标签: delphi google-api google-calendar-api gdata gdata-api