【发布时间】:2018-04-10 07:53:33
【问题描述】:
我正在尝试通过 Delphi REST 控件将事件插入到我的 Google 日历中,但我不确定在哪里将访问令牌添加到我的请求中。
我的代码如下所示:
var
evt : String;
begin
ResetRESTComponentsToDefaults;
RESTClient.BaseURL := 'https://www.googleapis.com/calendar/v3';
RESTClient.Authenticator := OAuth2_GoogleCalendar;
RESTRequest.Resource := 'calendars/primary/events';
evt:='{"summary":"test","description":"test","id":"06824945162f4204bfdc041ae1bbae85","start":{"date":"2018-04-10"},"end":{"date":"2018-04-10"},"guestsCanInviteOthers":false,"visibility":"private"}'
RESTRequest.AddParameter('access_token',OAuth2_GoogleTasks.AccessToken,pkHTTPHEADER);
RESTRequest.Method := TRESTRequestMethod.rmPOST;
RESTRequest.Body.Add(evt,ctAPPLICATION_JSON);
RESTRequest.Execute;
end;
范围是https://www.googleapis.com/auth/calendar
如果我像这样发送它,我会出现这个错误:
{
"error":
{
"errors":
[
{
"domain":"global",
"reason":"required",
"message":"Login Required",
"locationType":"header",
"location":"Authorization"
}
]
,
"code":401,
"message":"Login Required"
}
}
将?access_token={accessToken} 附加到我得到的网址的末尾
错误 400,解析错误。
我应该在哪里将访问令牌添加到请求中?
【问题讨论】:
标签: rest delphi google-api google-calendar-api google-oauth