gpt4 book ai didi

rest - Delphi 在哪里将访问 token 附加到谷歌 REST 请求?

转载 作者:行者123 更新时间:2023-12-03 18:35:02 25 4
gpt4 key购买 nike

我正在尝试通过 Delphi REST 控件将事件插入到我的 Google 日历中,但我不确定在哪里将访问 token 添加到我的请求中。我的代码如下所示:

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,解析错误。

我应该在哪里将访问 token 添加到请求中?

最佳答案

自从我使用 Delphi 以来,我已经帮不上什么忙了,但是在添加访问 token 方面,您有两种选择。

首先是将其作为参数添加到基本 url

?access_token=TokenHere

第二种选择是在您的请求中将其作为授权 header 发送,即不记名 token 。
Authorization : Bearer cn389ncoiwuencr

经过一番谷歌搜索,我找到了 this
FIdHTTP.Request.CustomHeaders.FoldLines := False;
FIdHTTP.Request.CustomHeaders.Add('Authorization:Bearer ' + txtToken.Text);

关于rest - Delphi 在哪里将访问 token 附加到谷歌 REST 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49748240/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com