• Login
  • Register

DNN Forums

A community discussion page. We're starting from scratch, so...let's get the party started!

Google Calendars API with Django — Error 403, Missing valid API key

You are not authorized to post a reply.

New Member

New Member

    We're trying to use the Google Calendars API in our Django project, when I try python manage.py runserver I get a 404 error, and when I click the link it provides me I get this:

      "error": {
        "code": 403,
        "message": "The request is missing a valid API key.",
        "errors": [
            "message": "The request is missing a valid API key.",
            "domain": "global",
            "reason": "forbidden"
        "status": "PERMISSION_DENIED"

    I went to the developer console and made an API key, but I'm not really sure how to use it. I came across someone using the API key as part of the "context" variable when making a POST request, but I haven't even attempted submitting the form that is supposed to call the API; I'm getting this error on startup. I tried adding a key: [my API key] in my service account json file, but that did not fix anything.

    Here is the Calendars code we have:

    BASE_DIR = os.getcwd()
    CLIENT_SECRET_FILE = BASE_DIR + '\calendar_api\credentials.json'  # 'calender_key.json'
    SCOPES = 'https://www.googleapis.com/auth/calendar'
    scopes = [SCOPES]
    APPLICATION_NAME = 'Google Calendar API Python'
    class google_calendar_api:
        def build_service(self):
            credentials = ServiceAccountCredentials.from_json_keyfile_name(
            http = credentials.authorize(httplib2.Http())
            service = build('calendar', 'v3', http=http, cache_discovery=False)
            return service
        def create_event(self, calendar_id, start, end, desc, ):
            service = self.build_service()
            event = service.events().insert(calendarId=calendar_id, body={
                'start':{'dateTime':  start},
                'end':{'dateTime':  end},
            return event['id']
        def update_event(self,calendar_id, event_id, start, end, desc):
            service = self.build_service()
                event = service.events().get(calendarId=calendar_id, eventId=event_id).execute()
            except HttpError as e:
                if e.resp.status==404:
                    return self.create_event(calendar_id, start, end, desc)
            event["summary"]= desc
            event["description"]= desc
            updated_event = service.events().update(calendarId=calendar_id, eventId=event['id'], body=event).execute()
            return updated_event["id"]

    Veteran Member

    Veteran Member

      Can you explain to me how this is related to DNN?

      You are not authorized to post a reply.

      These Forums are dedicated to discussion of DNN Platform.

      For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

      1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
      2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
      3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
      4. No Flaming or Trolling.
      5. No Profanity, Racism, or Prejudice.
      6. Site Moderators have the final word on approving / removing a thread or post or comment.
      7. English language posting only, please.

      Would you like to help us?

      Awesome! Simply post in the forums using the link below and we'll get you started.

      Get Involved