Skip to content

Commit 8cd586b

Browse files
committed
1.20.3
1 parent 94dfcbb commit 8cd586b

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

GET_USER_ACCESS_TOKEN.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
import os
66

77
def GET_USER_ACCESS_TOKEN(login_code):
8+
print("Starting the process of getting the user access token.")
9+
810
# 配置文件路径
911
config_path='feishu-config.ini'
1012

1113
# 确保配置文件存在
1214
if not os.path.exists(config_path):
15+
print("The configuration file does not exist. Creating a new one.")
1316
with open(config_path, 'w') as f:
1417
pass
1518

@@ -19,6 +22,7 @@ def GET_USER_ACCESS_TOKEN(login_code):
1922

2023
# 确保 TOKEN 部分存在
2124
if not config.has_section('TOKEN'):
25+
print("The TOKEN section does not exist in the configuration file. Adding it.")
2226
config.add_section('TOKEN')
2327

2428
# 从配置文件获取参数
@@ -41,28 +45,33 @@ def GET_USER_ACCESS_TOKEN(login_code):
4145
"code": login_code
4246
}
4347

48+
print("Sending the request to get the user access token.")
4449
# 发起请求
4550
response = requests.post(url, headers=headers, data=json.dumps(payload))
4651
response_json = response.json()
4752

48-
# 检查响应状态码
53+
# 检查响应状态码
4954
if response.status_code != 200:
5055
print(f"HTTP Error: {response_json}")
5156
return None
5257

53-
# 检查响应体中的 code
58+
# 检查响应体中的 code
5459
if response_json.get('code') != 0:
5560
print(f"Response Error: {response_json}")
5661
return None
5762

58-
5963
# 更新配置文件
6064
if 'data' in response_json and 'access_token' in response_json['data']:
6165
config.set('TOKEN', 'user_access_token', response_json['data']['access_token'])
66+
# 如果存在 refresh_token,也保存到配置文件
67+
if 'refresh_token' in response_json['data']:
68+
print("Refresh token found. Updating the configuration file.")
69+
config.set('TOKEN', 'refresh_token', response_json['data']['refresh_token'])
6270
with open(config_path, 'w', encoding='utf-8') as configfile:
6371
config.write(configfile)
6472

65-
return response_json.get('data', {}).get('access_token')
73+
print("Finished getting the user access token.")
74+
return response_json.get('data', {}).get('access_token'), response_json.get('data', {}).get('refresh_token')
6675

6776

6877
def GET_USER_ACCESS_TOKEN_CMD():
@@ -82,10 +91,11 @@ def GET_USER_ACCESS_TOKEN_CMD():
8291
raise ValueError("login_code is required either in command line argument or in the configuration file.")
8392

8493
# 调用 GET_USER_ACCESS_TOKEN 函数,获取 user_access_token
85-
user_access_token = GET_USER_ACCESS_TOKEN(login_code)
94+
user_access_token, refresh_token = GET_USER_ACCESS_TOKEN(login_code)
8695

8796
# 打印结果
8897
print(f'user_access_token: {user_access_token}')
98+
print(f'refresh_token: {refresh_token}')
8999

90100

91101
# 主函数

0 commit comments

Comments
 (0)