2013-08-01 25 views
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) 

回答

1

不幸的是有沒有辦法解決這個。該帳戶被禁用,您將無法使用JWT斷言來執行任何有用的操作。

截至目前,在刪除/暫停用戶文件之前,您需要將用戶文件的所有權轉移給其他帳戶。拉出所有用戶的列表>所有用戶的所有文件>所有文件的所有權限。從那裏你可以解析本地的權限ID以獲得所需的數據。在我的環境中需要大約40分鐘時間才能提取這些數據。我相信這是第三方驅動程序(CloudLock和General Audit Tool和Flashpanel)爲獲取有用數據所做的事情。可能不是你想要的答案。

在這種情況下,抽取全局驅動結果而不需要斷言的API將非常有用。或者,能夠通過fileID以外的其他方式查詢權限會很好。希望這是路線圖。

相關問題