Google cloud platform 如何在GCP的python代码中使用pageSize或pageToken
这是我从github获得的python代码。运行它,我得到了300。但当我使用gcloud获取角色号时,我总共得到了479个角色。GCP支持人员告诉我需要使用pageSize。在哪里可以找到如何使用页面大小和页面大小的文档?在我下面的代码中,pageSize应该放在哪里?或者可能需要使用pageToken (gcptest):$gcloud iam角色列表| grep name | wc-l 479 (gcptest):$python quickstart.py 三百 def quickstart(): #[启动iam_快速启动] 导入操作系统Google cloud platform 如何在GCP的python代码中使用pageSize或pageToken,google-cloud-platform,Google Cloud Platform,这是我从github获得的python代码。运行它,我得到了300。但当我使用gcloud获取角色号时,我总共得到了479个角色。GCP支持人员告诉我需要使用pageSize。在哪里可以找到如何使用页面大小和页面大小的文档?在我下面的代码中,pageSize应该放在哪里?或者可能需要使用pageToken (gcptest):$gcloud iam角色列表| grep name | wc-l 479 (gcptest):$python quickstart.py 三百 def quickstar
from google.oauth2 import service_account
import googleapiclient.discovery
import pprint
# Get credentials
credentials = service_account.Credentials.from_service_account_file(
filename=os.environ['GOOGLE_APPLICATION_CREDENTIALS'],
scopes=['https://www.googleapis.com/auth/cloud-platform'])
# Create the Cloud IAM service object
service = googleapiclient.discovery.build(
'iam', 'v1', credentials=credentials)
# Call the Cloud IAM Roles API
# If using pylint, disable weak-typing warnings
# pylint: disable=no-member
response = service.roles().list().execute()
roles = response['roles']
print(type(roles))
print(len(roles))
如果name='main':
quickstart()您需要编写类似以下内容的代码:
roles = service.roles()
request = roles.list()
while request is not None:
role_list = request.execute()
# process each role here
for role in role_list:
print(role)
# Get next page of results
request = roles.list_next(request, role_list)
list\u next
方法的文档除了@JohnHanley的解决方案外,您还可以在方法的参数中添加查询参数。像这样
# Page size of 10
response = service.roles().list(pageSize=10).execute()
此列表
方法的定义