如何基于python對(duì)接釘釘并獲取access_token
1.首先注冊(cè)應(yīng)用,獲取 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.此時(shí)拿到的token就是access_token,可以用它來發(fā)送請(qǐng)求了
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
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. XML入門的常見問題(四)2. 無線標(biāo)記語言(WML)基礎(chǔ)之WMLScript 基礎(chǔ)第1/2頁3. WMLScript的語法基礎(chǔ)4. ASP中if語句、select 、while循環(huán)的使用方法5. xml中的空格之完全解說6. html小技巧之td,div標(biāo)簽里內(nèi)容不換行7. ASP中解決“對(duì)象關(guān)閉時(shí),不允許操作?!钡脑幃悊栴}……8. ASP動(dòng)態(tài)網(wǎng)頁制作技術(shù)經(jīng)驗(yàn)分享9. msxml3.dll 錯(cuò)誤 800c0019 系統(tǒng)錯(cuò)誤:-2146697191解決方法10. 解決ASP中http狀態(tài)跳轉(zhuǎn)返回錯(cuò)誤頁的問題
