Google Calendar API / Python : I can't delete event

Question:

when I want to delete an event with a "[email protected]" with this command (below), it’s work with my primary email but not with this "[email protected]":

 from __future__ import print_function import httplib2 import os
 
 from apiclient import discovery from oauth2client import file  import
 oauth2client from oauth2client import client from oauth2client import
 tools
 
 import datetime import requests
 
 SCOPES = 'https://www.googleapis.com/auth/calendar' CLIENT_SECRET_FILE
 = 'credentials.json' APPLICATION_NAME = 'Google Calendar API Python Quickstart' calendar_use = '[email protected]'
 
 def get_credentials():
     """Gets valid user credentials from storage.
 
     If nothing has been stored, or if the stored credentials are invalid,
     the OAuth2 flow is completed to obtain the new credentials.
 
     Returns:
         Credentials, the obtained credential.
     """
     home_dir = os.path.expanduser('~')
     credential_dir = os.path.join(home_dir, '.credentials')
     if not os.path.exists(credential_dir):
         os.makedirs(credential_dir)
     credential_path = os.path.join(credential_dir,'calendar-python-quickstart.json')
 
     store = oauth2client.file.Storage(credential_path)
     credentials = store.get()
     if not credentials or credentials.invalid:
         flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
         flow.user_agent = APPLICATION_NAME
         if flags:
             credentials = tools.run_flow(flow, store, flags)
         else: # Needed only for compatibility with Python 2.6
             credentials = tools.run(flow, store)
         print('Storing credentials to ' + credential_path)
     return credentials
 
 def deleteEvent():
     get_credentials()
     credentials = get_credentials()
     http = credentials.authorize(httplib2.Http())
     service = discovery.build('calendar', 'v3', http=http)
     x = requests.delete('https://www.googleapis.com/calendar/v3/calendars/[email protected]/events/xxxxxxxxxxxxxxxxx')
     print(x.text)
 
 deleteEvent()

But i get this error message, and i can’t find the answer.

{
  "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",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "CREDENTIALS_MISSING",
        "domain": "googleapis.com",
        "metadata": {
          "service": "calendar-json.googleapis.com",
          "method": "calendar.v3.Events.Delete"

When I open the link, which is write in the error code, I don’t find the anwser
However, I can already create event, but i can’t delete. Thanks for all

Asked By: Aragor

||

Answers:

I guess you don’t need to use request.delete (Because the request doesn’t get auth credentials) but something like

service.events().delete(calendarId=calendarId, eventId=eventId).execute()

you just need to set up proper calendarId, eventId

Answered By: svfat
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.