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
|
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}\n")
# 遍歷每個用戶
for user in users:
print("用戶 ID:", user.get('id', 'N/A'))
print("名稱:", user.get('name', 'N/A'))
print("用戶名:", user.get('username', 'N/A'))
print("電子郵件:", user.get('email', 'N/A'))
roles = user.get('roles', [])
if roles:
print("角色:", ', '.join(roles))
else:
print("角色: N/A")
avatar_urls = user.get('avatar_urls', {})
if avatar_urls:
print("頭像 URL:")
for size, url in avatar_urls.items():
print(f"- {size}: {url}")
else:
print("頭像 URL: N/A")
print("介紹:", user.get('description', 'N/A'))
print("個人資料連結:", user.get('link', 'N/A'))
print("----------------------")
else:
print("無法獲取用戶數據。狀態碼:", response.status_code)
|