在 Delphi 中将访问令牌附加到 google REST 请求的何处?
Where to attach access token to google REST request in Delphi?
我正在尝试通过 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}
附加到 url 的末尾,我得到
错误 400,解析错误。
我应该在哪里添加访问令牌到请求?
我帮不上什么忙 Delphi 自从我使用它以来已经有好几年了,但是关于添加访问令牌,您有两个选择。
首先是将它作为参数添加到基础 url
?access_token=TokenHere
第二个选项是根据您的请求将其作为授权发送 header 它是不记名令牌。
Authorization : Bearer cn389ncoiwuencr
经过一番谷歌搜索,我发现 this
FIdHTTP.Request.CustomHeaders.FoldLines := False;
FIdHTTP.Request.CustomHeaders.Add('Authorization:Bearer ' + txtToken.Text);
我正在尝试通过 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}
附加到 url 的末尾,我得到
错误 400,解析错误。
我应该在哪里添加访问令牌到请求?
我帮不上什么忙 Delphi 自从我使用它以来已经有好几年了,但是关于添加访问令牌,您有两个选择。
首先是将它作为参数添加到基础 url
?access_token=TokenHere
第二个选项是根据您的请求将其作为授权发送 header 它是不记名令牌。
Authorization : Bearer cn389ncoiwuencr
经过一番谷歌搜索,我发现 this
FIdHTTP.Request.CustomHeaders.FoldLines := False;
FIdHTTP.Request.CustomHeaders.Add('Authorization:Bearer ' + txtToken.Text);