Python调用飞书Api上传本表格

本文介绍如何使用Python通过飞书API上传表格,详细步骤包括获取企业自建应用的app_token和user_access_token。适合开发者在飞书文档协作中实现自动化操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Python调用飞书Api上传本表格

import requests
# https://open.feishu.cn/open-apis/authen/v1/index?redirect_uri=?&app_id=?_a1039072c9f8900c
class FeishuApi():
  def __init__(self,app_id,app_secret,code_x):
    self.app_id = app_id
    self.app_secret = app_secret
    self.code_x = code_x
  def app_access_token(self): # 获取企业自建应用app_token
    data = {
      "app_id":self.app_id,
      "app_secret":self.app_secret
    }
    app_token = requests.post("https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal", json=data)
    return app_token.json()

  def user_access_token(self):
    data = {
     "grant_type": "authorization_code",
     "code": self.code_x
    }
    headers = {
            "Authorization":"Bearer "+self.app_access_token()["tenant_access_token"]
        }
    user_token = requests.post("https://open.feishu.cn/open-apis/authen/v1/access_token", json=data ,headers=headers)
    return user_token.json()["data"]["access_token"]

if __name__ == '__main__':
    Fa = FeishuApi(app_id="",
                   app_secret="",
                   code_x = "")
    user_token = Fa.user_access_token()
    print(user_token)

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值