在Google Cloud Console中,为相应的Google Cloud项目分配bigquery.jobs.create权限。具体步骤如下:
打开Google Cloud Console。
选择您的Google Cloud项目。
转到“IAM和管理员”页面。
在页面上方,选择“添加”。
在“新成员”字段中输入您要授予权限的电子邮件地址。
为该用户分配“BigQuery Job用户”角色。
单击“保存”以保存更改。
此外,您还可以通过以下代码示例为用户授予bigquery.jobs.create权限:
from google.cloud import bigquery
from google.oauth2 import service_account
# Replace with the path to your service account key file
service_account_path = "/path/to/service_account.json"
# Replace with the ID of your Google Cloud project
project_id = "ppc-big-query"
# Replace with the email address of the user or service account
user_email = "user@example.com"
# Create a credentials object using the service account key file
credentials = service_account.Credentials.from_service_account_file(service_account_path)
# Create a BigQuery client using the credentials and project ID
client = bigquery.Client(credentials=credentials, project=project_id)
# Create a policy object granting the bigquery.jobs.create permission to the user
policy = {
"bindings": [
{
"role": "roles/bigquery.jobUser",
"members": [
"user:" + user_email
]
}
]
}
# Set the policy for the project
client.set_iam_policy(requested_policy=policy)