这篇文章主要讲解了python对接钉钉并获取access_token的方法,内容清晰明了,对此有兴趣的小伙伴可以学习一下,相信大家阅读完之后会有帮助。
1.首先注册应用,获取 appkey、appsecret
api_url = "https://oapi.dingtalk.com/gettoken?appkey=%s&appsecret=%s"%(appkey,appsecret) def get_token(): # try: res = requests.get(api_url) if res.status_code == 200: str_res = res.text token = (json.loads(str_res)).get('access_token') return token
2.此时拿到的token就是access_token,可以用它来发送请求了
def departList(): # 所有部门信息 url = 'https://oapi.dingtalk.com/department/list?access_token={}'.format(get_token()) ret = json.loads(requests.get(url).text) department = ret.get('department') departList = [] for department_info in department: departdict = {} departdict['name'] = department_info.get('name') departdict['id'] = department_info.get('id') departdict['parentid'] = department_info.get('parentid') departList.append(departdict) return departList
看完上述内容,是不是对python对接钉钉并获取access_token的方法有进一步的了解,如果还想学习更多内容,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。