• Hi, i get “access token” (wp_oauth plugin). How create post with REST API?
    url is “localhost:8080/blog/wp-json/wp/v2/posts”?
    how to make?

    $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;

    https://ww.wp.xz.cn/plugins/rest-api/

Viewing 1 replies (of 1 total)
  • Thread Starter rogeriopavan1984

    (@rogeriopavan1984)

    ok. 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}}

Viewing 1 replies (of 1 total)

The topic ‘Create post with access_token’ is closed to new replies.