How to debug error 401/403 for Google Calendar API?

{
  "error": {
    "code": 403,
    "message": "Method doesn't allow unregistered callers (callers without established identity). Please use API Key or other form of API consumer identity to call this API.",
    "errors": [
      {
        "message": "Method doesn't allow unregistered callers (callers without established identity). Please use API Key or other form of API consumer identity to call this API.",
        "domain": "global",
        "reason": "forbidden"
      }
    ],
    "status": "PERMISSION_DENIED"
  }
}

i am being thrown this error after trying to user Google Calendar API’s insert function.

import React, { useState, useEffect} from 'react';
import './home.css';
import {gapi} from 'gapi-script'

function Home() {
  
  const [val, setVal] = useState("schedule a dinner at Denny's from 6pm to 8pm?");
 
  
  const makeGoogleCalendarApiCall = async () => {
    const token = localStorage.getItem('token');
    if (!token) {
      console.error("No OAuth token found, please log in again.");
      return;
    }
  
    gapi.load('client', async () => {
      try {
        await gapi.client.load('calendar', 'v3');
        console.log('Google Calendar API loaded successfully');
        console.log('token in gapi client load', token)
        // Set the OAuth token
        gapi.client.setToken({ access_token: token });
  
      } catch (error) {
        console.error('Error loading Calendar API or making API call:', error);
      }
    });
  };
  

 const click = async () => {
   const apiKey2 = //GPT API KEY
   const apiUrl = 'https://api.openai.com/v1/chat/completions'
   const tok = localStorage.getItem('token')
   console.log('tok: ', tok)
  makeGoogleCalendarApiCall()
  try {
     const result = await fetch(apiUrl, {
       method: 'POST',
       headers: {
         'Content-Type': 'application/json',
         'Authorization': `Bearer ${apiKey2}`,
       },
       body: JSON.stringify({
         model: "gpt-3.5-turbo",
         messages: [
           { role: "system", content: "You are a helpful assistant." },
           { role: "user", content: `Please provide the following event details in JSON format using ${val}: Summary, Location, Start Time, End Time. For example, if the user says 'schedule dinner tomorrow from 6pm to 8pm at home', the output should be structured JSON like this:
             {
               "summary": "Dinner",
               "location": "Home",
               "start": "6pm",
               "end": "8pm"
             }
             Convert the start and end times to RFC3339 format and the year is 2024. If you are not confident in filling out the output, or if user does not provide information, leave it empty. If end time is left empty and start is filled, assume the end time is one hour later. Respond with only the JSON format do not say anything else.` }
         ],
         max_tokens: 100,
         temperature: 0.7,
       }),
     });


     const data = await result.json();
     const reply = data.choices[0].message.content;


     console.log('OpenAI Response:', reply);
     const eventData = JSON.parse(reply); 


     console.log('Extracted Event Data:', eventData);


    


     const event = {
       'summary': eventData.summary,
       'location': eventData.location,
       'start': {
         'dateTime': eventData.start,
         'timeZone': 'America/Los_Angeles',
       },
       'end': {
         'dateTime': eventData.end,
         'timeZone': 'America/Los_Angeles',
       },
       'recurrence': [
         'RRULE:FREQ=DAILY;COUNT=2'
       ],
       
     };
      
     

     console.log('outside insert')
     console.log(localStorage.getItem('token'));  // Ensure a token is present
      gapi.client.calendar.events.insert({
        calendarId: 'primary',
        resource: event,
      }).then((response) => {
        console.log('Event created:', response.result.htmlLink);
        window.open(response.result.htmlLink); // Open the event link
      }).catch((error) => {
        console.error('Error creating event:', error);
      })
        
      return eventData;

   } catch (error) {
     console.error("Error response:", error);
   }
 };


 const change = event => {
   setVal(event.target.value);
 };


 return (
   <div>
     <input
       onChange={change}
       value={val}
       className="input"
     />
     <button className="button" onClick={click}></button>
   </div>
 );
}


export default Home;

essentially, I am trying to take in user input and plug that into OpenAI API which will be plugged into Calendar API so I can create an event. so for example, if i were to input “schedule me a dinner at Denny’s from 6pm to 8pm”, this would be turned into a JSON through OpenAI API and then GCal API will take the JSON and insert it as an event. this is one segment of code, i have one or two other files that handles Google login. which makes me wonder if the GIS login has anything to do with this since? also, im relatively new to programming so excuse my code if the structure/method is not the best.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật