javagoogle-cloud-platform

Get Google Cloud Project Number using its Id


I have Google Cloud Service account and projectId and want to get projectNumber programmatically from Java.

enter image description here

How can I get it?

Basically I have Service Account and want to use it for granting role "roles/storage.legacyBucketWriter" for the account "project-XXXXXXX@storage-transfer-service.iam.gserviceaccount.com" in the Google Cloud Storage Bucket.


Solution

  • I think GCP did not provide an API to map a project ID to a project number. But they did provide a project list API, after you get the list of the projects. You can map the project number by yourself.