Create Google Cloud Project with Cloud Resource Manager API

后端 未结 2 701
无人共我
无人共我 2021-01-17 00:40

I\'m trying to create a new project in the Google Cloud Platform using the Cloud Resource Manager API. It all works fine when I use it through the API explorer however I don

2条回答
  •  死守一世寂寞
    2021-01-17 01:37

    Like Alex says, you ask for scopes during OAuth authentication. One way to easily authenticate and obtain a Oauth access token is doing:

    gcloud beta auth application-default login --scopes=https://www.googleapis.com/auth/cloudplatformprojects

    As you can see, you can specify the scopes you want to gcloud and it will take care of authentication for you.

    Then, you should be able to create a project calling:

    curl -H "Content-Type: application/json" -H "Authorization: Bearer $(gcloud beta auth application-default print-access-token)" -X POST -d '{"name": "project example","projectId": "my-project-example-1234"}' https://cloudresourcemanager.googleapis.com/v1/projects?fields=response

    Here, you are passing the access token obtained when you made Oauth authentication. This should be taken care of by the client libraries for you when you get the application default credentials.

提交回复
热议问题