404 "Domain not found." when trying to query Calendar Resources list.

1,416 views
Skip to first unread message

Benjamin Thompson

unread,
Apr 6, 2016, 5:02:15 PM4/6/16
to Google API Python Client
I am using the Python client library in Python 3.5 on a Mac. I have created a project from a Google account with super-admin rights on the domain, created some Service Account credentials and downloaded them in JSON form to crr-service-secret.json, and granted all four scopes to the project ID. Yet every time I run the below code, I get an error that reads:

googleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/admin/directory/v1/customer/my_customer/resources/calendars?alt=json returned "Domain not found.">


I have searched and searched for similar issues anywhere online. I seem to be the only person experiencing this. Calls to other API endpoints work just fine. I'm pulling my hair out trying to figure out what's going wrong with this. Does anyone know?

from oauth2client.service_account import ServiceAccountCredentials
from apiclient.discovery import build
import json
from httplib2 import Http


credentials = ServiceAccountCredentials.from_json_keyfile_name(
'crr-service-secret.json',
scopes=scopes
)
http = credentials.authorize(Http())
directory = build('admin', 'directory_v1', http=http)

response = directory.resources().calendars().list(customer='my_customer')
print(response.execute(http=http))


Akshay Pratap Singh

unread,
Jun 7, 2016, 12:21:06 PM6/7/16
to Google API Python Client
To access Calendar resource of Admin SDK, you need to create a credentials that act as domain-wide delegation of authority.
Below is the updated code.

from oauth2client.service_account import ServiceAccountCredentials
from apiclient.discovery import build
import json
from httplib2 import Http


credentials = ServiceAccountCredentials.from_json_keyfile_name(
'crr-service-secret.json',
scopes=scopes
)

# Use this sub email as the subject to delegate on behalf of that user
account_sub = 'f...@email.com'

delegate_credentials = credentials.create_delegated(account_sub)

http = delegate_credentials.authorize(Http())

directory = build('admin', 'directory_v1', http=http)

response = directory.resources().calendars().list(customer='my_customer')
print(response.execute(http=http))
Reply all
Reply to author
Forward
0 new messages