简体   繁体   English

在 React-app 前端使用 Google 日历

[英]Using Google Calendar in React-app Front-end

I know this question is not exactly related to existing code but I want to be able to integrate Google Calendar API in my React project.我知道这个问题与现有代码并不完全相关,但我希望能够在我的 React 项目中集成 Google Calendar API。 I am wondering is it possible to be able to integrate this Google Calendar without backend directly in the React Application?我想知道是否可以在没有后端的情况下直接在 React 应用程序中集成这个谷歌日历? For example I want to be able to give people opportunity to book meetings from the website.例如,我希望能够让人们有机会从网站预订会议。 When they book a meeting I want to be able to see it in my calendar in Google Account.当他们预订会议时,我希望能够在我的 Google 帐户日历中看到它。 Is this possible or they have to login with their accounts and book it in my calendar or how it is working?这是可能的还是他们必须使用他们的帐户登录并在我的日历中预订或它是如何工作的? I found google documentation about this:我找到了关于这个的谷歌文档:

https://developers.google.com/calendar/quickstart/js

But I am not sure if that what I want is possible.但我不确定我想要的是否可能。 I also registered my API key and get my Client ID:我还注册了我的 API 密钥并获得了我的客户 ID:

const CALENDAR_ID ="XXXXXXXXXXXXXXXX.apps.googleusercontent.com";
const API_KEY = "XXXXXXXXXXXXXXXXX";
let url = `https://www.googleapis.com/calendar/v3/calendars/${CALENDAR_ID}/events?key=${API_KEY}`;

But when I try to perform call in POSTMAN I get:但是当我尝试在 POSTMAN 中执行调用时,我得到:

{
    "error": {
        "code": 401,
        "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
        "errors": [
            {
                "message": "Login Required.",
                "domain": "global",
                "reason": "required",
                "location": "Authorization",
                "locationType": "header"
            }
        ],
        "status": "UNAUTHENTICATED"
    }
}

So maybe I am doing it wrong.所以也许我做错了。 So anyone to have done something like this and can help me?所以有人做过这样的事情并且可以帮助我吗? I would really appreciate it, thanks!我真的很感激,谢谢!

Your API key or client-id will allow your app to ask for consent from the user in order to get the access token and be able to use the requested API.您的 API 密钥或客户端 ID 将允许您的应用程序征求用户同意以获取访问令牌并能够使用请求的 API。 In your case, since you want to add people (invitees) to your calendar, it is really you who should be asked for consent.在您的情况下,由于您想将人员(受邀者)添加到您的日历中,因此应该征求您的同意。

You can see that the only way to allow your app to make requests to the Calendar API on your behalf is for the app to have access to your access or refresh tokens, which would be insecure to bake into the front end.您可以看到,允许您的应用程序代表您向日历 API 发出请求的唯一方法是让应用程序访问您的访问或刷新令牌,这在前端是不安全的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM