本教程均已发送到指定群聊为例
开发之前首先需进入飞书开放平台注册应用
飞书开放平台
拿到应用的 APP_ID 和 APP_SECRET
1. 获取应用的access_token
def get_access_token(APP_ID, APP_SECRET):
url = 'https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal'
headers = {
'Content-Type': "application/json; charset=utf-8"
}
data = {
'app_id': APP_ID,
'app_secret': APP_SECRET
}
res = requests.post(url, headers=headers, json=data).json()
return res['tenant_access_token']
2. 获取发送目的地的id(如用户id)
可选择根据用户邮箱或者手机号查找,也可同时使用
def get_user_id(token):
url = 'https://open.feishu.cn/open-apis/contact/v3/users/batch_get_id?user_id_type=union_id'
headers = {
'Authorization': "Bearer " + token,
'Content-Type': "application/json; charset=utf-8"
}
# data = {
# 'user_id_type': 'union_id',
# }
json = {
# "emails": [
# "zhangsan@