是否可以使用 google 的 python api 更改融合表的权限?
我可以使用服务帐户成功创建表,但该表是在客户端电子邮件 (xxxx@gce-play.iam.gserviceaccount.com) 下创建的,而不是我个人的 gmail帐户。
如果不是,我不应该使用 ServiceAccounts 进行授权吗?该作业需要在没有人工交互的情况下运行(即不将 oauth2 链接粘贴到浏览器中)。
为了完整起见,我用两种方式创建了表格
Fusion Table Python Client Library
def create_service(service='fusiontables',version='v2'):
credentials = ServiceAccountCredentials.from_json_keyfile_name(keyfile, scopes)
http = httplib2.Http()
credentials.authorize(http)
return discovery.build(service, version, http=http)
service = create_service()
service.table().insert(body={...}).execute()
http = httplib2.Http()
http = credentials.authorize(http)
http.request(
uri='https://www.googleapis.com/fusiontables/v2/tables',
method='POST',
headers={'Content-Type': 'application/json; charset=UTF-8'},
body=json.dumps({...}),
)
答案详情(感谢下方的@RodMcChesney)
按照下面接受的答案中的建议,我使用了 Drive API .特别是我使用了 drive client library .
注意:在创建表或服务帐户之前,请确保您已在 Google 控制台中启用 Drive API
ft_scope = 'https://www.googleapis.com/auth/fusiontables'
drive_scope = 'https://www.googleapis.com/auth/drive'
scopes = [ft_scope,drive_scope]
keyfile='sa_key.json'
# create drive and fusion table service (using method from above)
ft=create_service()
drive = create_service('drive')
# create table
ft.table().insert(body={...}).execute()
# get table id
id=drive.files().list().execute()['items'][0]['id']
# add permissions for 'anyone'
permission={'type': 'anyone','role': 'reader'}
drive.permissions().insert(fileId=id,body=permission).execute()
请您参考如下方法:
您可以使用 Drive Permissions API创建表后更改表的权限。
