Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot Create Post. #8

Open
raffaelecolleo opened this issue Feb 7, 2018 · 9 comments
Open

Cannot Create Post. #8

raffaelecolleo opened this issue Feb 7, 2018 · 9 comments

Comments

@raffaelecolleo
Copy link

raffaelecolleo commented Feb 7, 2018

Hi there,
I am trying to create a post using jSON Api and jSON Api User.
My username is administrator so should be ok and Password does not have & or # in it.

Here's what I am doing:

var nonce = jQuery.getJSON( "https://www.example.com/api/get_nonce?json=get_nonce&controller=posts&method=create_post" );
console.log(nonce);
// ATTENTION: cookie was created on a login page and stored at localStorage.
var dataString = "controller=posts&method=create_post&cookie=" + localStorage.getItem("cookie") + "&nonce=" + nonce.responseJSON.nonce + "&post_type=my-custom-type&title=Post Created by APP";
console.log(dataString);
jQuery.ajax({
type: "GET",
url:"https://www.example.com/api/posts/create_post?",
data: dataString,
crossDomain: true,
cache: false,
success: function(data){
console.log(JSON.stringify(data));
},
error: function(data){
console.log(JSON.stringify(data));
}
});

I am getting back this error:
{"readyState":4,"responseText":"{\"status\":\"error\",\"error\":\"Your 'nonce' value was incorrect. Use the 'get_nonce' API method.\"}","responseJSON":{"status":"error","error":"Your 'nonce' value was incorrect. Use the 'get_nonce' API method."},"status":403,"statusText":"Forbidden"}

Any Ideas on how to solve this?

Thanks.

@pimedia
Copy link
Owner

pimedia commented Feb 7, 2018 via email

@raffaelecolleo
Copy link
Author

With JSON API User Plus is a Subscriber allowed to create posts?

@pimedia
Copy link
Owner

pimedia commented Feb 7, 2018 via email

@emmjk
Copy link

emmjk commented Apr 9, 2018

even though i'v loged in i still get the same results as the one mentioned above , The bad thing is if i try to write a post request from a browser it works fine but the same request doesnt work if requested from a postman with result from postman being the same as mentioned above and the result from a browser being status ok and post id and some other parameter . I think you need not to run away from this one bro , you need to fix this .

@emmjk
Copy link

emmjk commented Apr 9, 2018

Also something just came through my mind , To get as error that says "Your 'nonce' value was incorrect. Use the 'get_nonce' API method." is actually because the nonce is verified to not being valid as per source code available (Nonce is verified with wp_verify_nonce() function ) So how can you say its a log in issue even though the error is due to nonce verification failure that has appeared for a logged in user like me as explained above . I strongly think your argument of loged in user is of important but it is the case that will happen if the user did not provide authentication cookie from his request to create a post to a wordpress site . But if authentication cookie is given as one of the parameter as shown above by raffaelcolleo it crashes the loged in user issue and the main thing should be nonce verification "if statement) . Please try to go through your code to verify about that .

@pimedia
Copy link
Owner

pimedia commented Apr 10, 2018 via email

@emmjk
Copy link

emmjk commented Apr 12, 2018

Oky , I went through your website to get the JSON Api plus plugin , It seems your plugin allows even non registered users to be able to write a post to my wordpress site . But what i want is a plugin that allows only registerd and loged in user to write a post on a wordpress based site but from an android application am making . Do you have any recommendations for that ?

@raffaelecolleo
Copy link
Author

Ok. I bought 6 days ago the Single License. Sent emails to m [dot] ali [dot] qureshi [at] gmail [dot] com and no reply.

I need to know where I can download the plugin.

Any Ideas?
Thanks

@pimedia
Copy link
Owner

pimedia commented Apr 26, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants