create post wp rest api 2 with oauth
-
hi, guys. I looked example:
$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; //echo $access_key; $options = array ( 'http' => array ( 'ignore_errors' => true, 'method' => 'POST', 'header' => array ( 0 => 'authorization: Bearer'.$access_key, 1 => 'Content-Type: application/x-www-form-urlencoded', ), 'content' => http_build_query( array ( 'title' => 'Hello World', 'content' => 'Hello. I am a test post. I was created by the API', 'tags' => 'tests', 'categories' => 'API', )), ), ); $context = stream_context_create( $options ); $response = file_get_contents( 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/posts/new/', false, $context ); $response = json_decode( $response );
I can use this in wp rest api 2?
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘create post wp rest api 2 with oauth’ is closed to new replies.