我正在使用 Drive API 检查我的 Google Apps 域。我成功地创建了一项服务,但是当我在域上有一个暂停的用户时,我试图获取我所有用户的权限 ID 失败。使用我的 get_about 函数会导致 401 Unauthorized : Invalid Credentials。有没有办法解决这个错误?我应该以某种方式创建不同类型的服务吗?现在我被迫跳过那个用户。
#Passing in a already created user service
def get_about(service):
return service.about().get().execute()
这是我创建服务的地方:
class DriveService(object):
"""
The main entry class to constructing the google drive api client service
We wrap the service so it can be used as normal but with some error
handling provided
"""
raw_service = None
http = None
auth_scope = 'https://www.googleapis.com/auth/drive'
def __init__(self, user_email):
key_file_path = os.path.join(os.path.split(__file__)[0],
SERVICE_ACCOUNT_PEM_FILE)
with open(key_file_path, 'rb') as f:
key = f.read()
credentials = SignedJwtAssertionCredentials(SERVICE_ACCOUNT_EMAIL,
key,
scope=self.auth_scope,
prn=user_email)
self.user_email = user_email
self.http = credentials.authorize(httplib2.Http())
try:
self.raw_service = build('drive', 'v2', http=self.http,
requestBuilder=BackoffHttpRequest,
)
except:
import pdb
pdb.set_trace()
def __getattr__(self, attr):
try:
return object.__getattribute__(self, attr)
except AttributeError:
return getattr(self.raw_service, attr)