我正在使用Drive API检查我的Google Apps域。我成功创建了一个服务,但当我的域上有一个暂停的用户时,尝试获取所有用户的权限I失败。使用我的get_about函数会导致一个401Unitrated: Invalid凭据。有什么办法可以绕过这个错误吗?我应该以某种方式创建一种不同类型的服务吗?现在,我被迫跳过该用户。
#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)
发布于 2013-08-02 23:01:51
不幸的是,这是没有办法的。该帐户已禁用,您将无法使用JWT断言对其执行任何有用的操作。
从现在起,在删除/挂起用户文件之前,您需要将用户文件的所有权转移到另一个帐户。拉取所有用户>所有用户的所有文件>所有文件的所有权限的列表。从那里,您可以在本地解析所述用户名的权限ids,以获取您想要的数据。在我的环境中提取这些数据大约需要40分钟。我相信这就是第三方驱动应用程序(CloudLock、通用审计工具和Flashpanel)为了获取有用数据所做的事情。可能不是你想要的答案。
在这种情况下,无需断言即可获取全局驱动器结果的API将非常有用。或者,能够通过fileID以外的其他方式查询权限会更好。希望这已经在路线图上了。
https://stackoverflow.com/questions/18000965
复制相似问题