Reputation: 1038
I want to list all the projects that I have access but it only returns 1 record when I call the ListProjects method from BigQueryClient class.
I verify that I have access for at-least 2 projects by trying to run the code below:
BigQueryClient client = BigQueryClient.Create("project1");
var result = client.ExecuteQuery("SELECT col1 FROM `project1.dataset1.table1`", null) //this returns the data from project1
BigQueryClient client = BigQueryClient.Create("project2");
var result = client.ExecuteQuery("SELECT col1 FROM `project2.dataset2.table2`", null) //this returns the data from project2
Both code above returns the data. But when I try to get all the projects using the ListProjects method, it only returns 1 record:
BigQueryClient client = BigQueryClient.Create(string.Empty);
var projects = client.ListProjects(); //this method only returns 1 record
Is there a missing in my code so that I can see all the projects from google BigQuery?
Upvotes: 1
Views: 433
Reputation: 1038
The string.Empty or irrelevant in BigQueryClient.Create
doesn't matter. It needs to have a role on the GCP Project that you want to include in the service account.
In my case, I follow the steps below:
There is a delayed about 2 minutes before it takes effect.
Upvotes: 1
Reputation: 2773
BigQueryClient client = BigQueryClient.Create(string.Empty);
BigQueryClient client = BigQueryClient.Create("irrelevant");
PagedEnumerable<ProjectList, CloudProject> projects = client.ListProjects();
foreach (CloudProject project in projects)
{
Console.WriteLine($"{project.ProjectId}: {project.FriendlyName}");
}
try other thing go to your old project and enable big query. BigQuery is automatically enabled in new projects. To activate BigQuery in a pre-existing project, go to Enable the BigQuery API.
I think either you provide right project id or service key. https://cloud.google.com/bigquery/docs/authentication/service-account-file
Upvotes: 0