0

Using cloud function - trying to make get call to get the project name and with the id - https://cloud.google.com/resource-manager/docs/creating-managing-projects#listing_projects

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

 project = crm.projects().get(name="projects/"+projectId).execute()

`

6
  • The link you put in your question has example Python code. What is the problem? Commented Oct 21, 2022 at 1:57
  • @JohnHanley - If I have a project id - prj-mmm-test-11234 and how can I get the name for the id. That's what I am looking for, the code is just giving me the get project. Commented Oct 21, 2022 at 2:06
  • Again what is the problem? You are using the correct code to get the project details. The member name is the Project Name. Commented Oct 21, 2022 at 2:18
  • @JohnHanley - what is projectId. Because I want to give the value for project id and i want to get the name for that project id. Not all the project name, only the given project id Commented Oct 21, 2022 at 2:26
  • @user3713336 your code is correct, if you have your project_id in projectId variable, this code will execute (given the auth goes through) and will store the Project instance into the project variable. If this doesn't work for you, tell us what exactly doesn't work, what the error is or any details that you think could help
    – jabbson
    Commented Oct 21, 2022 at 3:23

1 Answer 1

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

project = crm.projects().get(name="projects/"+projectId).execute()
project_name = project['displayName']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.