当前位置: 首页 > 知识库问答 >
问题:

delphi google日历Api事件插入

郑松
2023-03-14

我试图使用delphi REST控件将一个事件插入到我的google日历中。

这是迄今为止的代码:

procedure TForm1.TestGoogleRestParams;
var
  i: Integer;
  jsonObjEventResource,jsonObjStart,jsonObjEnd: TJSONObject;
begin
  try
    jsonObjEventResource:=TJSONObject.Create();
    jsonObjStart:=TJSONObject.Create();
    jsonObjEnd:=TJSONObject.Create();

    jsonObjEventResource.AddPair(TJSONPair.Create('summary','test'));
    jsonObjEventResource.AddPair(TJSONPair.Create('description','Testing'));
    jsonObjEventResource.AddPair(TJSONPair.Create('id',LowerCase('06824945162F4204BFDC041AE1BBAE85')));

    jsonObjStart.AddPair(TJSONPair.Create('date',FormatDateTime('yyyy-mm-dd',Now)));

    jsonObjEventResource.AddPair(TJSONPair.Create('start',jsonObjStart));

    jsonObjEnd.AddPair(TJSONPair.Create('date',FormatDateTime('yyyy-mm-dd',Now)));

    jsonObjEventResource.AddPair(TJSONPair.Create('end',jsonObjEnd));

    jsonObjEventResource.AddPair(TJSONPair.Create('guestsCanInviteOthers',TJSONBool. Create(false)));
    jsonObjEventResource.AddPair(TJSONPair.Create('visibility','private'));

    mem_Test.Lines.Add(TJson.Format(jsonObjEventResource));
    //mem_Test.Lines.Add(jsonObjEventResource.ToJSON);
    RESTRequest.Method := TRESTRequestMethod.rmPOST;
    RESTRequest.Body.ClearBody;
    RESTRequest.AddBody(jsonObjEventResource);
    RESTRequest.Execute;
  finally
    //jsonObjEventResource.Free;
    //jsonObjStart.Free;
    //jsonObjEnd.Free;
  end;
end;

我使用的范围是:https://www.googleapis.com/auth/calendar.
基本URL:https://www.googleapis.com/calendar/v3
资源URI:日历/主要/事件

我确实获得了访问令牌和刷新令牌,但无法发布请求。这是我收到的错误:

{
  "error":
  {
    "errors":
    [
            {
        "domain":"global",
        "reason":"required",
        "message":"Login Required",
        "locationType":"header",
        "location":"Authorization"
      }
    ]
,
    "code":401,
    "message":"Login Required"
  }
}

使用以下uri:https://www.googleapis.com/calendar/v3/calendars/primary/events

我该如何解决这个问题?

如果我不调用这个方法而只调用< code>RESTRequest。执行;我得到了所有现有事件的列表。

共有1个答案

陶超
2023-03-14

“:”无效凭据“

表示您使用的客户端id和客户端机密不正确。您应该从Google Developer控制台下载一个新文件,然后重试。

选项2:

尝试对用户进行身份验证。可能是访问令牌已过期,需要刷新

 类似资料:
  • 我是新手,但我想将google API与PHP结合使用,但它不起作用。我已经创建了

  • 我正在扩展一个PHP应用程序,它允许管理员创建事件并为这些事件分配特定用户。但是,在用户被列为可分配之前,我会检查用户的日历,看看他们是否可用。 我已经使用EWS为Exchange构建了一次,并使用FindItem方法在给定的时间段内检索用户电子邮件地址的事件,但我在Google日历API中很难找到等效的事件。 Events和FreeBusy Call似乎都需要特定用户的calendarId,这对

  • 我正在寻找在特定日期添加事件的日历视图,如下所示: 默认的日历视图可以帮助我做同样的事情,或者有任何其他的API可以帮助获得像上面这样的结果吗? 让我知道! 谢谢

  •  说明 调用方法1: $.f2eAct.calendar(el,options); 函数说明: 生成日历 参数说明: 参数名 类型 说明 备注 el string DOM元素对象 必要 calendar boolean 是否生成日历 默认true time string/int 当前日历时间,如不传,默认当前系统时间; 如传,时间格式为2015/8/3 10:00:00或Unix时间戳 无 sh

  • 用户已经通过Google Actions使用google sign in获得了gmail帐户的授权。现在,我需要插入谷歌日历的用户事件列表,但我面临一些问题或不知道如何建立它。我对日历api非常陌生,所以请任何人指导我如何解决它。 如何使用从google操作收到的idtoken访问用户的google日历 如何将多个事件插入用户日历

  • 我使用OAuth对我的应用程序进行了身份验证,并使用日历API对其进行了测试。一切正常。我还为事件API使用了“快速添加”方法,效果很好。但是当我尝试使用以下代码插入时 我得到以下错误: 致命错误:未捕获异常“apiServiceException”,消息为“调用POST时出错 https://www.googleapis.com/calendar/v3/calendars/myemail@gma