0
我正在使用雲端硬盤API來檢查我的Google Apps域。我成功創建了一項服務,但在域中有一個被暫停的用戶時,未能嘗試獲取所有用戶的權限ID。使用我的get_about函數會導致401未授權:無效憑證。無論如何要解決這個錯誤?我應該以某種方式創建不同類型的服務嗎?現在我被迫跳過那個用戶。獲取Google雲端硬盤中已暫停用戶的權限ID
#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)