0

i am using service account auth2client.service_account and googleapiclient to connect to google calendars and create events, my issue is my events are creating and also confirmed using list events, but the events are not being visible in google calendars.

from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient.discovery import build
SERVICE_ACCOUNT_FILE = 'chat-json.json'
SCOPES = ['https://www.googleapis.com/auth/calendar']

@app.route('/add_event/', methods=['POST'])
def add_event():
    # Authenticate using service account credentials
    credentials = ServiceAccountCredentials.from_json_keyfile_name(
        SERVICE_ACCOUNT_FILE, scopes=SCOPES)

    service = build('calendar', 'v3', credentials=credentials)
    
    event = {
        'summary': 'Test Meeting',
        'location': 'Test Location',
        'description': 'Test Description',
        'start': {
            'dateTime': (datetime.utcnow() + timedelta(days=1)).isoformat(),
            'timeZone': 'America/Los_Angeles',
        },
        'end': {
            'dateTime': (datetime.utcnow() + timedelta(days=1, hours=1)).isoformat(),
            'timeZone': 'America/Los_Angeles',
        },
    }

    print(event)

    try:
        # Insert the event into the calendar
        event = service.events().insert(calendarId='primary', body=event).execute()
        print(event)
        return jsonify({'status': 'success', 'eventId': event['id']})
    except Exception as e:
        return jsonify({'status': 'error', 'message': str(e)})
Default guest permissions
Add invitations to my calendar
When I respond to the invitation in email

Sample of one of the event created, when go to html link it gives no requested event found

{'kind': 'calendar#event', 'etag': '"34578432000"', 'id': 'j4clmqbhch2d0k', 'status': 'confirmed', 'htmlLink': 'https://www.google.com/calendar/event?eid=ajRjbG1xYmhjZ2ZwZW01ODE3MzBraDJkMGsgY2hhdC1haUBwcm8tcGFyay00MTc2MDguaWFtLmdzZXJ2aWNlYWNjb3VudC5jb20', 'created': '2024-03-18T20:29:49.000Z', 'updated': '2024-03-18T20:29:49.216Z', 'summary': 'Python Meeting', 'description': 'A meeting to discuss Python projects.', 'location': '800 Howard St., San Francisco, CA 94103', 'creator': {'email': '[email protected]', 'self': True}, 'organizer': {'email': '[email protected]', 'self': True}, 'start': {'dateTime': '2024-03-20T03:29:47Z', 'timeZone': 'America/Los_Angeles'}, 'end': {'dateTime': '2024-03-20T04:29:47Z', 'timeZone': 'America/Los_Angeles'}, 'iCalUID': '[email protected]', 'sequence': 0, 'reminders': {'useDefault': True}, 'eventType': 'default'}

I can't find what the issue is, is it in the configurations or permissions.

1
  • Have you configured domain wide deligation to the workspace account. Also I can see where you are denoting the user on your domain to impersonate. Where is that part of the code Commented Mar 18, 2024 at 21:43

1 Answer 1

0

I was asking the same question and then i realized i was looking at the year 2015 because google calendar docs were written in 2015 and examples were using year 2015 so you might wanna check that.

If this doesn't solve your problem then make sure your calendar is displayed(that little checkbox on the left side of your calendar should be checked).

Good luck.

Sign up to request clarification or add additional context in comments.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.