请求wordpress json api记录

第三方平台连接wp-json接口需要借助plugin生成token

JWT Authentication for WP-API

image-20230128151015431

不太行 要手动修改apache .htaccess文件

API Bearer Auth

image-20230128152534220

API Bearer Auth – WordPress 插件 | WordPress.org China 简体中文

  • 获取Bearer token
1
2
3
4
5
6
7
curl --location --request POST 'http://localhost/wp-json/api-bearer-auth/v1/login' \
--header 'Content-Type: application/json' \
--data-raw '{
"username": "beixian",
"password": "123456",
"client_name": "dealar"
}'
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
{
"wp_user": {
"data": {
"ID": "1",
"user_login": "beixian",
"user_nicename": "beixian",
"user_email": "",
"user_url": "http://localhost",
"user_registered": "2023-01-04 06:32:18",
"user_activation_key": "",
"user_status": "0",
"display_name": "beixian"
},
"ID": 1,
"caps": {
"administrator": true
},
"cap_key": "wp_capabilities",
"roles": [
"administrator"
],
"allcaps": {
"switch_themes": true,
"edit_themes": true,
"activate_plugins": true,
"edit_plugins": true,
"edit_users": true,
"edit_files": true,
"manage_options": true,
"moderate_comments": true,
"manage_categories": true,
"manage_links": true,
"upload_files": true,
"import": true,
"unfiltered_html": true,
"edit_posts": true,
"edit_others_posts": true,
"edit_published_posts": true,
"publish_posts": true,
"edit_pages": true,
"read": true,
"level_10": true,
"level_9": true,
"level_8": true,
"level_7": true,
"level_6": true,
"level_5": true,
"level_4": true,
"level_3": true,
"level_2": true,
"level_1": true,
"level_0": true,
"edit_others_pages": true,
"edit_published_pages": true,
"publish_pages": true,
"delete_pages": true,
"delete_others_pages": true,
"delete_published_pages": true,
"delete_posts": true,
"delete_others_posts": true,
"delete_published_posts": true,
"delete_private_posts": true,
"edit_private_posts": true,
"read_private_posts": true,
"delete_private_pages": true,
"edit_private_pages": true,
"read_private_pages": true,
"delete_users": true,
"create_users": true,
"unfiltered_upload": true,
"edit_dashboard": true,
"update_plugins": true,
"delete_plugins": true,
"install_plugins": true,
"update_themes": true,
"install_themes": true,
"update_core": true,
"list_users": true,
"remove_users": true,
"promote_users": true,
"edit_theme_options": true,
"delete_themes": true,
"export": true,
"manage_woocommerce": true,
"view_woocommerce_reports": true,
"edit_product": true,
"read_product": true,
"delete_product": true,
"edit_products": true,
"edit_others_products": true,
"publish_products": true,
"read_private_products": true,
"delete_products": true,
"delete_private_products": true,
"delete_published_products": true,
"delete_others_products": true,
"edit_private_products": true,
"edit_published_products": true,
"manage_product_terms": true,
"edit_product_terms": true,
"delete_product_terms": true,
"assign_product_terms": true,
"edit_shop_order": true,
"read_shop_order": true,
"delete_shop_order": true,
"edit_shop_orders": true,
"edit_others_shop_orders": true,
"publish_shop_orders": true,
"read_private_shop_orders": true,
"delete_shop_orders": true,
"delete_private_shop_orders": true,
"delete_published_shop_orders": true,
"delete_others_shop_orders": true,
"edit_private_shop_orders": true,
"edit_published_shop_orders": true,
"manage_shop_order_terms": true,
"edit_shop_order_terms": true,
"delete_shop_order_terms": true,
"assign_shop_order_terms": true,
"edit_shop_coupon": true,
"read_shop_coupon": true,
"delete_shop_coupon": true,
"edit_shop_coupons": true,
"edit_others_shop_coupons": true,
"publish_shop_coupons": true,
"read_private_shop_coupons": true,
"delete_shop_coupons": true,
"delete_private_shop_coupons": true,
"delete_published_shop_coupons": true,
"delete_others_shop_coupons": true,
"edit_private_shop_coupons": true,
"edit_published_shop_coupons": true,
"manage_shop_coupon_terms": true,
"edit_shop_coupon_terms": true,
"delete_shop_coupon_terms": true,
"assign_shop_coupon_terms": true,
"administrator": true
},
"filter": null
},
"access_token": "dcc21431b90fd8acac52d934ea1955981b68c27d48ea16dc3bad09d9f0aff6e2",
"expires_in": 86400,
"refresh_token": "8ae0503926687677e6e5237031b1876cecfb81ce7dd982461dee8bd50ca48e97"
}
  • Refresh token
1
2
3
curl --location --request POST 'http://localhost/wp-json/api-bearer-auth/v1/tokens/refresh' \
--header 'Content-Type: application/json' \
--data-raw '{"token": "8ae0503926687677e6e5237031b1876cecfb81ce7dd982461dee8bd50ca48e97", "client_name": "dealar"}'
1
2
3
4
{
"access_token": "f07dc29c8b001ec143e7d6e6ebd110fb5fb07c078c9cb6e384a7cef5a479f1bf",
"expires_in": 86400
}

Wordpree media

上传media文件接口

1
2
3
4
5
curl --location --request POST 'http://localhost/wp-json/wp/v2/media' \
--header 'content-disposition: attachment; filename=beixian.png' \
--header 'Authorization: Bearer f07dc29c8b001ec143e7d6e6ebd110fb5fb07c078c9cb6e384a7cef5a479f1bf' \
--header 'Content-Type: image/jpeg' \
--data-binary '@/Users/casonmo/Pictures/Photos Library.photoslibrary/originals/9/9E00792B-5CD0-4233-851B-121320A61618.jpeg'
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
{
"id": 36,
"date": "2023-01-28T07:42:13",
"date_gmt": "2023-01-28T07:42:13",
"guid": {
"rendered": "http://localhost/wp-content/uploads/2023/01/beixian.jpg",
"raw": "http://localhost/wp-content/uploads/2023/01/beixian.jpg"
},
"modified": "2023-01-28T07:42:13",
"modified_gmt": "2023-01-28T07:42:13",
"slug": "beixian",
"status": "inherit",
"type": "attachment",
"link": "http://localhost/beixian/",
"title": {
"raw": "beixian",
"rendered": "beixian"
},
"author": 1,
"comment_status": "open",
"ping_status": "closed",
"template": "",
"meta": [],
"permalink_template": "http://localhost/?attachment_id=36",
"generated_slug": "beixian",
"description": {
"raw": "",
"rendered": "<p class=\"attachment\"><a href='http://localhost/wp-content/uploads/2023/01/beixian.jpg'><img width=\"300\" height=\"300\" src=\"http://localhost/wp-content/uploads/2023/01/beixian-300x300.jpg\" class=\"attachment-medium size-medium\" alt=\"\" decoding=\"async\" loading=\"lazy\" srcset=\"http://localhost/wp-content/uploads/2023/01/beixian-300x300.jpg 300w, http://localhost/wp-content/uploads/2023/01/beixian.jpg 1024w, http://localhost/wp-content/uploads/2023/01/beixian-150x150.jpg 150w, http://localhost/wp-content/uploads/2023/01/beixian-768x768.jpg 768w, http://localhost/wp-content/uploads/2023/01/beixian-324x324.jpg 324w, http://localhost/wp-content/uploads/2023/01/beixian-416x416.jpg 416w, http://localhost/wp-content/uploads/2023/01/beixian-100x100.jpg 100w\" sizes=\"(max-width: 300px) 100vw, 300px\" /></a></p>\n"
},
"caption": {
"raw": "",
"rendered": ""
},
"alt_text": "",
"media_type": "image",
"mime_type": "image/jpeg",
"media_details": {
"width": 1024,
"height": 1024,
"file": "2023/01/beixian.jpg",
"filesize": 66568,
"sizes": {
"medium": {
"file": "beixian-300x300.jpg",
"width": 300,
"height": 300,
"filesize": 14751,
"mime_type": "image/jpeg",
"source_url": "http://localhost/wp-content/uploads/2023/01/beixian-300x300.jpg"
},
"large": {
"file": "beixian-1024x1024.jpg",
"width": 1024,
"height": 1024,
"filesize": 65430,
"mime_type": "image/jpeg",
"source_url": "http://localhost/wp-content/uploads/2023/01/beixian-1024x1024.jpg"
},
"thumbnail": {
"file": "beixian-150x150.jpg",
"width": 150,
"height": 150,
"filesize": 6292,
"mime_type": "image/jpeg",
"source_url": "http://localhost/wp-content/uploads/2023/01/beixian-150x150.jpg"
},
"medium_large": {
"file": "beixian-768x768.jpg",
"width": 768,
"height": 768,
"filesize": 48019,
"mime_type": "image/jpeg",
"source_url": "http://localhost/wp-content/uploads/2023/01/beixian-768x768.jpg"
},
"woocommerce_thumbnail": {
"file": "beixian-324x324.jpg",
"width": 324,
"height": 324,
"filesize": 16413,
"uncropped": false,
"mime_type": "image/jpeg",
"source_url": "http://localhost/wp-content/uploads/2023/01/beixian-324x324.jpg"
},
"woocommerce_single": {
"file": "beixian-416x416.jpg",
"width": 416,
"height": 416,
"filesize": 22105,
"mime_type": "image/jpeg",
"source_url": "http://localhost/wp-content/uploads/2023/01/beixian-416x416.jpg"
},
"woocommerce_gallery_thumbnail": {
"file": "beixian-100x100.jpg",
"width": 100,
"height": 100,
"filesize": 4004,
"mime_type": "image/jpeg",
"source_url": "http://localhost/wp-content/uploads/2023/01/beixian-100x100.jpg"
},
"full": {
"file": "beixian.jpg",
"width": 1024,
"height": 1024,
"mime_type": "image/jpeg",
"source_url": "http://localhost/wp-content/uploads/2023/01/beixian.jpg"
}
},
"image_meta": {
"aperture": "0",
"credit": "",
"camera": "",
"caption": "",
"created_timestamp": "0",
"copyright": "",
"focal_length": "0",
"iso": "0",
"shutter_speed": "0",
"title": "",
"orientation": "0",
"keywords": []
}
},
"post": null,
"source_url": "http://localhost/wp-content/uploads/2023/01/beixian.jpg",
"missing_image_sizes": [],
"_links": {
"self": [
{
"href": "http://localhost/wp-json/wp/v2/media/36"
}
],
"collection": [
{
"href": "http://localhost/wp-json/wp/v2/media"
}
],
"about": [
{
"href": "http://localhost/wp-json/wp/v2/types/attachment"
}
],
"author": [
{
"embeddable": true,
"href": "http://localhost/wp-json/wp/v2/users/1"
}
],
"replies": [
{
"embeddable": true,
"href": "http://localhost/wp-json/wp/v2/comments?post=36"
}
],
"wp:action-unfiltered-html": [
{
"href": "http://localhost/wp-json/wp/v2/media/36"
}
],
"wp:action-assign-author": [
{
"href": "http://localhost/wp-json/wp/v2/media/36"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
}

请求wordpress json api记录
https://cason.work/2023/01/28/请求wordpress-json-api记录/
作者
Cason Mo
发布于
2023年1月28日
许可协议