rogeriopavan1984
Forum Replies Created
Viewing 4 replies - 1 through 4 (of 4 total)
-
Forum: Plugins
In reply to: [WordPress REST API (Version 2)] Create post with access_tokenok. I install “JSON Basic Authentication”. I created this code:
$headers = array ( 'Authorization' => 'Basic ' . base64_encode( 'rogerio_pavan' . ':' . '270184' )); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'http://localhost:8080/blog/wp-json/wp/v2/posts'); $data = array( 'title' => 'Hello World', 'content_raw'=>'no matters', 'date'=>'2016-08-01T14:00:00+10:00' ); curl_setopt($curl, CURLOPT_POSTFIELDS, array( 'method' => 'POST', 'headers' => $headers, 'body' => $data)); $post = curl_exec($curl );and return
{"code":"rest_cannot_create","message":"Sorry, you are not allowed to create new posts.","data":{"status":401}}Forum: Plugins
In reply to: [WP OAuth Server (OAuth Authentication)] create post wp rest api 2 with oauthwithin the wordpress / plugins
Forum: Plugins
In reply to: [WP OAuth Server (OAuth Authentication)] create post wp rest api 2 with oauthok
Forum: Plugins
In reply to: [WP OAuth Server (OAuth Authentication)] create post wp rest api 2 with oauththanks!
I try:
//get token $curl = curl_init( 'localhost:8080/blog/oauth/token' ); curl_setopt( $curl, CURLOPT_POST, true ); curl_setopt( $curl, CURLOPT_POSTFIELDS, array( 'client_id' => 'GT9DiTPY6WNjGOp7aGvm6hsvCQ4xi4', 'client_secret' => 'HTebdz1TV1KrGd0xQDUofe1JeusMEm', 'grant_type' => 'password', 'username' => 'rogerio_pavan', 'password' => '270184', ) ); curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1); $auth = curl_exec( $curl ); print_r ($auth); $auth = json_decode($auth); $access_key = $auth->access_token; //call api wprestapi $headers = array ( 'Authorization' => 'Bearer ' . $access_key); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'http://localhost:8080/blog/wp-json/wp/v2/posts'); $data = array( 'title' => 'Hello World' ); curl_setopt($curl, CURLOPT_POSTFIELDS, array( 'method' => 'POST', 'headers' => $headers, 'body' => $data) ); $post = curl_exec($curl );server answer: “{“code”:”rest_cannot_create”,”message”:”Sorry, you are not allowed to create new posts.”,”data”:{“status”:401}}”
The params ‘method’, ‘headers’, ‘body’ i see in documentation wp rest api 2.
I’ll see the code plugin wp rest api 2.
Viewing 4 replies - 1 through 4 (of 4 total)