Google cloud platform 尝试在google cloud shell中列出项目并出现错误

Google cloud platform 尝试在google cloud shell中列出项目并出现错误,google-cloud-platform,python-requests,google-api-python-client,Google Cloud Platform,Python Requests,Google Api Python Client,我试图通过cloudshell终端的以下python代码列出我的帐户可以使用的项目 from googleapiclient import discovery from oauth2client.client import OAuth2Credentials as creds crm = discovery.build( 'cloudresourcemanager', 'v1', http=creds.authorize(httplib2.Http())) filter = "

我试图通过cloudshell终端的以下python代码列出我的帐户可以使用的项目

from googleapiclient import discovery
from oauth2client.client import OAuth2Credentials as creds
crm = discovery.build(
    'cloudresourcemanager', 'v1', http=creds.authorize(httplib2.Http()))

filter = "name:project a"
projects = crm.projects().list(filter=filter).execute()
但是在执行以下行之后,我得到了这个错误:

crm = discovery.build('cloudresourcemanager', 'v1', http=creds.authorize(httplib2.Http()))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unbound method authorize() must be called with OAuth2Credentials instance as first argument (got Http instance instead)
crm=discovery.build('cloudresourcemanager','v1',http=creds.authorize(httplib2.http()))
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
TypeError:必须使用OAuth2Credentials实例作为第一个参数调用unbound方法authorize()(取而代之的是Http实例)
我是谷歌云和python的新手,请帮忙谢谢

from google.cloud import resource_manager
   
client = resource_manager.Client()
for project in client.list_projects():
    print(project)

这将提供由环境变量设置的当前上下文中的所有项目
GOOGLE\u APPLICATION\u CREDENTIALS

您需要首先使用服务帐户或
OAuth2Credentials进行授权