API календаря Google – расписание встречPython

Программы на Python
Anonymous
API календаря Google – расписание встреч

Сообщение Anonymous »

В календарь Google вы можете добавить «Расписание встреч»
Изображение
Это события, которые периодически повторяются. Но они не созданы из обычных событий. Они создаются точно по расписанию.
Как мне получить к ним доступ с помощью Google API?
Я пробовал service.events().list< /code> и service.events().instances, и ни один из них, похоже, не возвращает его.
Я использую python
Вот мой код, использующий service.events ().экземпляры

Код: Выделить всё

import os
from dotenv import load_dotenv

import datetime
import time
import schedule

from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError

load_dotenv()

TG_BOT_TOKEN = os.getenv("TG_BOT_TOKEN")
TG_CHAT_ID = os.getenv("TG_CHAT_ID")
SCOPES = ["https://www.googleapis.com/auth/calendar"]

def main():
creds = None
if os.path.exists("token.json"):
creds = Credentials.from_authorized_user_file(
"token.json", SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
"credentials.json", SCOPES
)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open("token.json", "w") as token:
token.write(creds.to_json())

try:
service = build("calendar", "v3", credentials=creds)
now = datetime.datetime.utcnow().isoformat() + 'Z'
week_later = (datetime.datetime.utcnow() +
datetime.timedelta(days=7)).isoformat() + 'Z'
# Call the Calendar API
instances_result = (
service.events()
.instances(
calendarId="primary",
timeMin=now,
timeMax=week_later,
maxResults=100,
eventId='recurringEventId',
)
.execute()
)
instances = instances_result.get("items", [])
if not instances:
print("No upcoming instances found.")
return

# Prints the start and name of the next 10 events
for instance in instances:
start = instance["start"].get(
"dateTime", instance["start"].get("date"))
print(start, instance["summary"])

except HttpError as error:
print(f"An error occurred: {error}")

if __name__ == "__main__":
main()
После запуска программы я получаю сообщение «Предстоящие экземпляры не найдены».

Подробнее здесь: https://stackoverflow.com/questions/781 ... t-schedule

Вернуться в «Python»