Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在代码中添加自己的凭据而不是使用默认凭据:Google Compute Api_Python_Api_Google Compute Engine_Gcloud_Credentials - Fatal编程技术网

Python 在代码中添加自己的凭据而不是使用默认凭据:Google Compute Api

Python 在代码中添加自己的凭据而不是使用默认凭据:Google Compute Api,python,api,google-compute-engine,gcloud,credentials,Python,Api,Google Compute Engine,Gcloud,Credentials,因此,我将此代码用于计算引擎api。我的问题是,如何在此代码中添加我自己的凭据而不是默认凭据 以下是链接: 请参阅第页,了解验证请求的不同方法的说明以及一些代码示例。查看左侧菜单中的其他页面(最佳实践、使用SA进行身份验证、使用用户凭据和api密钥进行身份验证)以获取详细信息 from pprint import pprint from googleapiclient import discovery from oauth2client.client import GoogleCredentia

因此,我将此代码用于计算引擎api。我的问题是,如何在此代码中添加我自己的凭据而不是默认凭据

以下是链接:

请参阅第页,了解验证请求的不同方法的说明以及一些代码示例。查看左侧菜单中的其他页面(最佳实践、使用SA进行身份验证、使用用户凭据和api密钥进行身份验证)以获取详细信息

from pprint import pprint
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials.get_application_default()
service = discovery.build('compute', 'v1', credentials=credentials)
# Project ID for this request.
project = 'my-project'  # TODO: Update placeholder value.
# Name of the region scoping this request.
region = 'my-region'  # TODO: Update placeholder value.
# Name of the TargetPool resource to return.
target_pool = 'my-target-pool'  # TODO: Update placeholder value.
request = service.targetPools().get(project=project, region=region, targetPool=target_pool)
response = request.execute()
# TODO: Change code below to process the `response` dict:
pprint(response)