1.首先注册应用,获取 appkey、appsecret

api_url = "https://oapi.dingtalk.com/gettoken"%(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

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com

评论“如何基于python对接钉钉并获取access_token”

暂无“如何基于python对接钉钉并获取access_token”评论...