Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

飞书无法获取open_id #2609

Open
xiehaitang opened this issue Apr 24, 2024 · 3 comments
Open

飞书无法获取open_id #2609

xiehaitang opened this issue Apr 24, 2024 · 3 comments

Comments

@xiehaitang
Copy link

重现步骤

飞书无法获取open_id,现有的get_feishu_open_id有问题,需要更改如下:
def get_feishu_open_id(email):
url = "https://open.feishu.cn/open-apis/contact/v3/users/batch_get_id?user_id_type=open_id"
payload = json.dumps({"emails": email})
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + get_feishu_access_token()
}
resp = requests.request("POST", url, headers=headers, data=payload)
result = []
# 确保响应状态码是200,表示请求成功
if resp.status_code == 200:
resp_json = resp.json()
if resp_json.get("code") == 0:
# 遍历user_list中的每个user_info字典
for user_info in resp_json["data"]["user_list"]:
result.append(user_info.get("user_id"))
else:
logger.error(f"API错误: {resp_json.get('msg')}")
else:
logger.error(f"请求失败,状态码:{resp.status_code}")
logger.debug(f"返回结果: {result}")
return result

预期外的结果

正常获取到open_id

日志文本

No response

版本

1.8.5

部署方式

Docker

是否还有其他可以辅助定位问题的信息?比如数据库版本等

No response

@LeoQuote
Copy link
Collaborator

  1. 可以试试 master 版本
  2. 欢迎 pr

@xiehaitang
Copy link
Author

master 版本飞书api也是几年前的,根据我这个截图修改即可。
image
def get_feishu_open_id(email):
url = "https://open.feishu.cn/open-apis/contact/v3/users/batch_get_id?user_id_type=open_id"
payload = json.dumps({"emails": email})
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + get_feishu_access_token()
}
resp = requests.request("POST", url, headers=headers, data=payload)
result = []
# 确保响应状态码是200,表示请求成功
if resp.status_code == 200:
resp_json = resp.json()
if resp_json.get("code") == 0:
# 遍历user_list中的每个user_info字典
for user_info in resp_json["data"]["user_list"]:
result.append(user_info.get("user_id"))
else:
logger.error(f"API错误: {resp_json.get('msg')}")
else:
logger.error(f"请求失败,状态码:{resp.status_code}")
logger.debug(f"返回结果: {result}")
return result

@LeoQuote
Copy link
Collaborator

麻烦提个 pr , 谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants