007gzs / dingtalk-sdk

钉钉 dingding Python SDK。 DingTalk SDK for Python http://dingtalk-sdk.readthedocs.io/zh_CN/latest/
GNU General Public License v3.0
183 stars 56 forks source link

有计划新增日志方面的API吗? #21

Closed niulinlnc closed 5 years ago

niulinlnc commented 5 years ago

@钉钉最近增加了比较多的日志方面的API,大神有计划添加进来吗?

007gzs commented 5 years ago

issues里发下文档地址,我有空加下

niulinlnc commented 5 years ago

获取日志统计数据等等 https://open-doc.dingtalk.com/microapp/serverapi2/lhlow3

007gzs commented 5 years ago

master 最新代码已增加,你可以 pip install https://github.com/007gzs/dingtalk-sdk/archive/master.zip 之后测下,没问题的话我发布新

niulinlnc commented 5 years ago

def create(self, name, follower_user_id, label_ids, mobile, state_code='86', title=None, share_deptids=(), remark=None, address=None, company_name=None, share_userids=()): """ 添加外部联系人

    :param name: 名称
    :param follower_user_id: 负责人userId
    :param state_code: 手机号国家码
    :param mobile: 手机号
    :param label_ids: 标签列表
    :param title: 职位
    :param share_deptids: 共享给的部门ID
    :param remark: 备注
    :param address: 地址
    :param company_name: 企业名
    :param share_userids: 共享给的员工userId列表
    :return:
    """

    return self._top_request(
        "dingtalk.oapi.extcontact.create",
        {
            "contact": {
                'name': name,
                'follower_user_id': follower_user_id,
                'state_code': state_code,
                'mobile': mobile,
                'label_ids': label_ids,
                'title': title,
                'share_deptids': share_deptids,
                'remark': remark,
                'address': address,
                'company_name': company_name,
                'share_userid': share_userids
            }
        },
        result_processor=lambda x: x['userid']
    )

以上代码,我如果给标签label_ids 传一个数值列表,会报错,查看日志,发现请求参数label_ids 变成了 [[123456]],正常应该是[123456]

007gzs commented 5 years ago

你传的参数是 label_ids = 123456 还是 label_ids = [123456 ,]

niulinlnc commented 5 years ago

我传的label_ids=[123456],如果是多个标签,就是lable_ids=[12345,5678]这样子。

007gzs commented 5 years ago

import json print(json.dumps({'tt':[12345], 'dd': [12345,]})) 上面的在你的环境里运行下输出什么

niulinlnc commented 5 years ago

输出:{"tt": [12345], "dd": [12345]}

007gzs commented 5 years ago

client.extcontact.create('test', '123', [123], '123') 我试了下是[123]啊

【请求地址】: https://eco.taobao.com/router/rest 【请求参数】:{'contact': '{"name": "test", "follower_user_id": "123", "state_code": "86", "mobile": "123", "label_ids": [123], "title": null, "share_deptids": [], "remark": null, "address": null, "company_name": null, "share_userid": []}', 'method': 'dingtalk.oapi.extcontact.create', 'timestamp': '2019-07-03 21:47:02', 'format': 'json', 'v': '2.0', 'simplify': 'false', 'session': 123} 【错误信息】:{'error_response': {'code': 88, 'msg': 'ding talk error', 'sub_code': '40014', 'sub_msg': '不合法的access_token', 'request_id': 'ege4rh3xv4kj'}}

niulinlnc commented 5 years ago

谢谢指点,我知道原因了,本来我用的tbdingding里的api,传的是字典,晚上改了api后,去掉字典后,每行参数后面的逗号忘记删除造成的。

niulinlnc commented 5 years ago

def update(self, user_id, name, follower_user_id, label_ids, mobile, state_code='86', title=None, share_deptids=(), remark=None, address=None, company_name=None, share_userids=()): """ 更新外部联系人

    :param user_id: 该外部联系人的userId
    :param name: 名称
    :param follower_user_id: 负责人userId
    :param state_code: 手机号国家码
    :param mobile: 手机号
    :param label_ids: 标签列表
    :param title: 职位
    :param share_deptids: 共享给的部门ID
    :param remark: 备注
    :param address: 地址
    :param company_name: 企业名
    :param share_userids: 共享给的员工userId列表
    :return:
    """
    return self._top_request(
        "dingtalk.oapi.extcontact.update",
        {
            "contact": {
                "user_id": user_id,
                'name': name,
                'follower_user_id': follower_user_id,
                'state_code': state_code,
                'mobile': mobile,
                'label_ids': label_ids,
                'title': title,
                'share_deptids': share_deptids,
                'remark': remark,
                'address': address,
                'company_name': company_name,
                'share_userid': share_userids
            }
        }
    )

这段代码里,'share_deptids': share_deptids,与'share_userid': share_userids,好像写错 ,应该是 'share_dept_ids'与'share_user_ids' 参考:https://open-doc.dingtalk.com/microapp/serverapi2/nb93oa

007gzs commented 5 years ago

已修改

niulinlnc commented 5 years ago

其他测试都ok了。

007gzs commented 5 years ago

v1.3.0已发布

niulinlnc commented 5 years ago

谢谢