如何使用 Python 从 Asana API 访问自定义字段?

How can I access custom fields from Asana API using Python?

我正在尝试从我的 Asana 列表中提取自定义字段的值。我正在使用 Official Python client library for the Asana API v1.

我的代码目前看起来像这样;

import asana

api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
client = asana.Client.basic_auth(api_key)
me = client.users.me()
all_projects = next(workspace for workspace in me['workspaces'])
projects = client.projects.find_by_workspace(all_projects['id'])

for project in projects:
    if 'Example Project' not in project['name']:
        continue
    tasks = client.tasks.find_by_project(project['id'], {"opt_fields":"this.name,this.custom_fields"}, iterator_type=None)

    for task in tasks:
        if "Example Task" in task['name']:
            print "Matching task found."
            print task['name'] + " - " + str(task['id'])
            print task['custom_fields']
            print

我得到了输出;

Matching task found.
Example Task - 228660596773016
[None, None]

Matching task found.
Example Task 2 - 228660596773021
[None, None]

"None" 个值的数量等于自定义字段的数量。如何获取键名和值?我的最终目标是验证值并根据需要进行更新。

我进行了一些试验并设法重现了您遇到的问题。你能试试opt_fields":"this.name,custom_fields吗?