From bigquery resources you can use its client library (which makes use of the API) to get that information.
UPDATED 12/07/2021: JAVA API
Unfortunately this was take out of JAVA API BIGQUERY Client and there is no news if it will make a return. So, you wont be able to get such information from BigQuery latest client. You can see one discussion about it here.
Regardless of that you will be able to get that info using resource manager
. ( although you will need to have the information from the hierarchy above or at least the project name )
libraries used
import com.google.cloud.resourcemanager.v3.Project;
import com.google.cloud.resourcemanager.v3.ProjectName;
import com.google.cloud.resourcemanager.v3.ProjectsClient;
code
try (ProjectsClient projectsClient = ProjectsClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
Project prjct = projectsClient.getProject(name);
System.out.println(prjct.getProjectId());
System.out.println(prjct.getName()); # returns `projects/415104041262`
}
To setup DOM
and dependencies, you can check the official documentation for resource manager. Also, here is the link where can check the client used to get projects, project client
Workarounds:
Alternatively you can use other libraries and cmds to get that information, it makes use of bigquery python client library to get the information you are looking for:
from google.cloud import bigquery
from google.oauth2 import service_account
# key_path = "path/to/service_account.json"
key_path = "my-service-account-key.json"
credentials = service_account.Credentials.from_service_account_file(
key_path, scopes=["https://www.googleapis.com/auth/cloud-platform"],
)
client = bigquery.Client(credentials=credentials, project=credentials.project_id,)
print(client.get_service_account_email())
projects = client.list_projects(max_results=10)
for project in list(projects):
print(project.project_id)
print(project.numeric_id)
Note: follow this link for guidance on how to get a service account json.
output
bq-service-account-project-number@bigquery-account.iam.gserviceaccount.com
project id: my-project-id
project number: 7788990000xxx
Another options outside bigquery resources to get info about projects. You can get that information you will have to open google cloud shell
and perform the following command:
gcloud projects describe <my-project-id>
output:
createTime: '2015-10-20T10:12:09.452Z'
lifecycleState: ACTIVE
name: my-project-id
parent:
id: '111222333xxx'
type: folder
projectId: my-project-id
projectNumber: '777555000xxx'
Also, I'm leaving these links where you can get project related info:
Finally, If you are looking about why its difficult to get info from bigquery about projects I'm providing this link that discuss about resource-hierarchy.