权限和融合 Table API
Permissions and the Fusion Table API
是否可以使用 google 的 python api 更改融合 table 的权限?
我可以使用服务帐户成功创建 table,但是 table 在 client-email (xxxx@gce- play.iam.gserviceaccount.com) 而不是我的个人 gmail 帐户。
如果不是,我不应该使用 ServiceAccounts 进行授权吗?该作业需要 运行 无需人工交互(即无需将 oauth2 链接粘贴到浏览器中)。
为了完整起见,我用两种方式创建了 tables
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. In particular I used the drive client library。
注意:在创建 table 或服务帐户之前,请确保您已在 google 控制台[=18 中启用驱动器 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 后更改 table 的权限。
是否可以使用 google 的 python api 更改融合 table 的权限?
我可以使用服务帐户成功创建 table,但是 table 在 client-email (xxxx@gce- play.iam.gserviceaccount.com) 而不是我的个人 gmail 帐户。
如果不是,我不应该使用 ServiceAccounts 进行授权吗?该作业需要 运行 无需人工交互(即无需将 oauth2 链接粘贴到浏览器中)。
为了完整起见,我用两种方式创建了 tables
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. In particular I used the drive client library。
注意:在创建 table 或服务帐户之前,请确保您已在 google 控制台[=18 中启用驱动器 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 后更改 table 的权限。