0

i have implemented the authentication using allauth authentcation that is allowing me to logg in with google.It is successfully logging in .Now i want to work with Google Calendar and enabled the calendar API from developer console too.I dont know how to go on with it. When i log in through google also ask to allow acces to google calendar but i dont know how to get the list of event.When i tried the endpoint provided by Google(https://www.googleapis.com/calendar/v3/calendars/calendarId/acl) then its returns:

{
"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"
}

}

MoinKhan
  • 21
  • 4
  • Please note ,i have provided the the OAuth access token in header section while making a call to the endpoint mentioned. – MoinKhan Mar 10 '21 at 10:26
  • What is the request you made? Why do you want to get the list of the events with ACL? Why not use the [Events: list](https://developers.google.com/calendar/v3/reference/events/list) method to do it? – Kessy Mar 10 '21 at 14:13
  • i am struggling to integrate the google Api's with my django project . Actually i am trying to do make a todo app which have google based authenticatin and then using the calender to make todo app for that partiular user. Any links to blogs/project will be very helpfull.. thanks in advane – MoinKhan Mar 15 '21 at 08:55
  • Have you tried using the standard [python calendar API quickstart](https://developers.google.com/calendar/quickstart/python) and then do the modifications? – Kessy Mar 16 '21 at 16:50
  • Thanks it worked – MoinKhan Mar 18 '21 at 13:32
  • Can you share it as a solution so more people can benefit from it? – Kessy Mar 19 '21 at 16:23
  • https://stackoverflow.com/questions/66720449/missing-endtime-whie-inserting-to-calendar-event can you help me wit this – MoinKhan Mar 21 '21 at 06:33
  • @MoinKhan If you successfully accessed user's calendar, Can you help me with https://stackoverflow.com/questions/70270177/how-to-fix-504-gateway-time-out-while-connecting-to-google-calendar-api – anonymous Dec 10 '21 at 04:39

2 Answers2

0

I was able to work with the Google Calendar Api eventually and i integrate them in my django app .If anyone facing the same issue ,i am sharing the github link to my app .It is public you can go through my code .Correct me if i am wrong and am happy to clarify any doubts you have regarding the app .Check out the source code here.

Thank You.

MoinKhan
  • 21
  • 4
-1

Using the Google quickstart for Calendar on python and then use that sample to change the method to use did work when integrating it to the project.

This is the quickstart code:

from __future__ import print_function
import datetime
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials

# If modifying these scopes, delete the file token.json.
SCOPES = ['https://www.googleapis.com/auth/calendar.readonly']


def main():
    """Shows basic usage of the Google Calendar API.
    Prints the start and name of the next 10 events on the user's calendar.
    """
    creds = None
    # The file token.json stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    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())

    service = build('calendar', 'v3', credentials=creds)

    # Call the Calendar API
    now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time
    print('Getting the upcoming 10 events')
    events_result = service.events().list(calendarId='primary', timeMin=now,
                                        maxResults=10, singleEvents=True,
                                        orderBy='startTime').execute()
    events = events_result.get('items', [])

    if not events:
        print('No upcoming events found.')
    for event in events:
        start = event['start'].get('dateTime', event['start'].get('date'))
        print(start, event['summary'])


if __name__ == '__main__':
    main()
Kessy
  • 1,894
  • 1
  • 8
  • 15