对于自定义属性,Google 并未在其示例代码中提供使用示例。
Google 创建作业的示例并注释“使用自定义属性创建作业”,但实际上并未包含自定义属性的任何代码:
def sample_create_job(project_id, tenant_id, company_name, requisition_id,
language_code):
"""Create Job with Custom Attributes"""
client = talent_v4beta1.JobServiceClient()
# project_id = 'Your Google Cloud Project ID'
# tenant_id = 'Your Tenant ID (using tenancy is optional)'
# company_name = 'Company name, e.g. projects/your-project/companies/company-id'
# requisition_id = 'Job requisition ID, aka Posting ID. Unique per job.'
# language_code = 'en-US'
if isinstance(project_id, six.binary_type):
project_id = project_id.decode('utf-8')
if isinstance(tenant_id, six.binary_type):
tenant_id = tenant_id.decode('utf-8')
if isinstance(company_name, six.binary_type):
company_name = company_name.decode('utf-8')
if isinstance(requisition_id, six.binary_type):
requisition_id = requisition_id.decode('utf-8')
if isinstance(language_code, six.binary_type):
language_code = language_code.decode('utf-8')
parent = client.tenant_path(project_id, tenant_id)
job = {
'company': company_name,
'requisition_id': requisition_id,
'language_code': language_code
}
response = client.create_job(parent, job)
print('Created job: {}'.format(response.name))
如何为作业定义自定义属性?
以下内容适用于早期版本的 Talent Solution:
job['custom_attributes'] = {
'custom_name' : {'stringValues' : ['s0', 's1', 's2']},
...
}
我现在已经尝试过了:
from google.cloud.talent_v4beta1.types import CustomAttribute
job['custom_attributes'] = [
{
'key' : 'keyname',
'value': CustomAttribute(string_values=[valuestring], filterable=True)
}
]
但是当我尝试创建或更新作业时,会引发异常:TypeError: {'key': 'keyname', 'value': string_values: "valuestring"
filterable: true
} has type dict, but expected one of: bytes, unicode