WordPress.org

Support

Support » Plugins and Hacks » JSON API » Authentication and Create Post

Authentication and Create Post

  • I am trying to use this JSON-API to create a post for my wordpress site from within a Ruby program.

    However, after a get a nonce and make the post call I get this response error:

    “error”=>”You need to login with a user that has ‘edit_posts’ capacity.”

    How is a user supposed to “login” via a Ruby program? I am using the HTTParty gem for making my REST calls.

    Here is the code I am using:

    nonce_response = HTTParty.get "http://example.com/?json=get_nonce&controller=posts&method=create_post"
    puts nonce_response.code
    
    nonce_info = JSON.parse(nonce_response.body)
    puts nonce_info["status"]
    puts nonce_info["nonce"]
    puts nonce_info.inspect
    
    post_body = {:nonce => nonce_info["nonce"], :status => "draft", :title => "this is only a test", :content => "great content here!",
                 :categories => "Test"}
    
    post_response = HTTParty.post( "http://example.com/?json=create_post", :body => post_body)

    Thanks for any tips,

    –harris

    http://wordpress.org/plugins/json-api/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Authentication and Create Post’ is closed to new replies.
Skip to toolbar