Python 获取企业微信中微盘的文件列表

先说结论:企微api暂不支持获取微盘文件列表功能,且未来也不大可能支持.

过程:

一,首先按惯例,获取token

复制代码
import requests
def get_access_token(corpid, corpsecret):
    url = f"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={corpid}&corpsecret={corpsecret}"
    response = requests.get(url)
    data = response.json()
    return data.get('access_token')

怎么从企微中找到corpid, corpsecret,自行搜索

这一步顺顺利利,可以连接成功

二,我尝试去拿文件列表,脚本如下

复制代码
def get_file_message(access_token):
    url = f"https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_list?access_token={access_token}"
    data = {
        "spaceid": "s.1970325736989685.663049851sLo",
        "fatherid": "s.1970325736989685.663049851sLo",
        "sort_type": 1,
        "start": 0,
        "limit": 100
    }
    response = requests.post(url, json=data)
    return response.json()

怎么在企微中找到spaceid,也请自行搜索,我是用F12找到的

问题就出现在这一步,pycharm提示

{'errcode': 640008, 'errmsg': 'permision deny, hint: [1722830197123491071289534], from ip: 121.8.91.234, more info at https://open.work.weixin.qq.com/devtool/query?e=640008'}

进程已结束,退出代码为 0

点击错误提示的链接,显示如下图

说什么没有空间权限,WTF~

怎么会没有权限呢?我可是超级管理员呀,于是利用我的超级管理员权限在企微管理后台各种找各种设置无果,求助企微客服,老实了

企微官方技术支持-九九的解释进一步理解就是:

① 支持API创建微盘空间, 但不能以userid的身份创建,而是要以应用的身份创建,配置如下

②支持API上传文件,但是不支持用户上传文件,就算是管理员,也只能下载/预览文件

③支持API获取文件列表,但是仅支持获取API创建的空间的文件列表,而不支持用户在微盘客户端创建的空间, 所以才会有前文的报错:没有空间权限.

思考:为什么企业微信不提供此类api

微盘属于企微的收费服务之一,价格不菲(200元/人/年),如果api免费提供,那么就会被开发的第三方应用取代了.

相关推荐
嗯、.1 分钟前
Agent 路由架构的一次尝试:LangGraph + Swarm Handoff + 小模型 Router
人工智能·python·swarm·langgraph·multi-agent·model-routing
SunnyDays10114 分钟前
Java 实现插入和删除 Excel 行和列
java·python·excel
kels88995 分钟前
加密货币实时api的订单簿快照多久更新一次?
开发语言·笔记·python·金融·区块链
落日屿星辰7 分钟前
PyTorch 模型迁移到昇腾NPU 完整指南
人工智能·pytorch·python
SilentSamsara10 分钟前
类型注解进阶:Union、Optional、Any 与 Callable
开发语言·python·青少年编程
爱喝热水的呀哈喽10 分钟前
gpt:RAG步骤
人工智能·python·机器学习
Fleshy数模14 分钟前
课堂教学质量评估系统:基于加权欧氏距离的评分实现
python·llm
恣艺15 分钟前
Python 游戏开发与文件处理:PyGame + Turtle + openpyxl + python-docx + PyPDF2
开发语言·python·pygame
_山海23 分钟前
用langchain 通过text-embedding-3-small生成embedding
python·langchain·llm
毋语天29 分钟前
FastAPI 网络编程入门到实战:从 HTTP 协议到异步 API 开发
python·网络编程·fastapi·rest api·异步编程