1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
| | import requests |
| --- | --- |
| | |
| | # 发送 GET 请求获取用户数据 |
| | response = requests.get('http://your-wordpress-url/wp-json/wp/v2/users') |
| | |
| | # 检查请求是否成功 |
| | if response.status_code == 200: |
| | users = response.json() # 解析 JSON 数据 |
| | total_users = len(users) # 获取用户数量 |
| | print(f"Total Users: {total_users}\n") |
| | |
| | # 遍历每个用户 |
| | for user in users: |
| | print("User ID:", user.get('id', 'N/A')) |
| | print("Name:", user.get('name', 'N/A')) |
| | print("Username:", user.get('username', 'N/A')) |
| | print("Email:", user.get('email', 'N/A')) |
| | roles = user.get('roles', []) |
| | if roles: |
| | print("Roles:", ','.join(roles)) |
| | else: |
| | print("Roles: N/A") |
| | avatar_urls = user.get('avatar_urls', {}) |
| | if avatar_urls: |
| | print("Avatar URLs:") |
| | for size, url in avatar_urls.items(): |
| | print(f"- {size}: {url}") |
| | else: |
| | print("Avatar URLs: N/A") |
| | print("Description:", user.get('description', 'N/A')) |
| | print("Profile Link:", user.get('link', 'N/A')) |
| | print("----------------------") |
| | else: |
| | print("Failed to retrieve user data. Status code:", response.status_code) |
|