如何创建这个随机数?

how to create this nonce?

我需要一些帮助来理解这意味着什么:

https://wordpress.org/plugins/json-api/other_notes/#Method:-create_post

Required argument

nonce - available from the get_nonce method (call with vars controller=posts >and method=create_post)

我应该如何创建随机数?

我正在尝试:

wp_nonce_field( 'posts', 'create_post' );

请注意,您不必直接使用 wordpress 随机数功能,而是在 post 控制器中使用 Json Api 的给定方法。

您可以试试bbottema

的解决方法

First you need a nonce (Number used ONCE), which is a temporary key you'll use to be able to invoke the API with:

http://yourblog.com/?json=core.get_nonce&controller=posts&method=create_post&callback=?

This gives you a nonce number (be sure to use &callback=? as it marks the content as jsonp, or you'll get a similar -but invalid- nonce).

Then use this nonce to create a post:

http://yourblog.com/?json=posts.create_post&nonce='+nonce+'&title='+title+'&content='+content+'&status=publish (or draft, or leave it out altogether)

Make sure you have the 'posts' controller enabled in your wordpress plugin JSon API settings. Check this manual for what JSon data structures you can expect back from these calls.

Now, here's the tricky part: you need to be already logged into the wordpress site, because with this JSon API, you can't log in. I haven't figured that part out yet, so I'm still looking for a good solution myself. I tried manually posting and also width ajax but with limited results considering I'm missing a WordPress test cookie in my headers (at least this is the main difference I see when logging in from the site and doing it manually)

JSON API USER 不起作用,只有当您使用 ADMIN ROLE 帐户登录网站时它才会起作用!..否则它不会创建有效的随机数