在Delphi中,在何处将访问令牌附加到google REST请求?
我正试图通过Delphi REST控件将一个事件插入到我的Google日历中,但我不确定在哪里将访问令牌添加到我的请求中。在Delphi中,在何处将访问令牌附加到google REST请求?,rest,delphi,google-api,google-calendar-api,google-oauth,Rest,Delphi,Google Api,Google Calendar Api,Google Oauth,我正试图通过Delphi REST控件将一个事件插入到我的Google日历中,但我不确定在哪里将访问令牌添加到我的请求中。我的代码如下所示: var evt : String; begin ResetRESTComponentsToDefaults; RESTClient.BaseURL := 'https://www.googleapis.com/calendar/v3'; RESTClient.Authenticator := OAuth2_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}
附加到我获取的url的末尾错误400,解析错误
我应该在哪里向请求中添加访问令牌?我对Delphi帮助不大,因为我已经使用它多年了,但是关于添加访问令牌,您有两种选择 首先是将其作为参数添加到基本url上
?access_token=TokenHere
第二种选择是在您的请求中将其作为授权头发送,并将其作为承载令牌发送
Authorization : Bearer cn389ncoiwuencr
通过谷歌搜索,我发现
FIdHTTP.Request.CustomHeaders.FoldLines := False;
FIdHTTP.Request.CustomHeaders.Add('Authorization:Bearer ' + txtToken.Text);