title: create post wordpress.com using rest api
body: <p>I want to make php app to create post on wordpress.com using REST api.</p>
  
  <p>I use this code:</p>
  
  <pre><code>&lt;?php
  
  $curl = curl_init( 'https://public-api.wordpress.com/oauth2/token' );
  curl_setopt( $curl, CURLOPT_POST, true );
  curl_setopt( $curl, CURLOPT_POSTFIELDS, array(
  'client_id' =&gt; 12345,
  'redirect_uri' =&gt; 'http://example.com/wp/test.php',
  'client_secret' =&gt; 'L8RvNFqyzvqh25P726jl0XxSLGBOlVWDaxxxxxcxxxxxxx',
  'code' =&gt; $_GET['code'], // The code fromthe previous request
  'grant_type' =&gt; 'authorization_code'
  ) );
  curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1);
  
  $auth = curl_exec( $curl );
  $secret = json_decode($auth);
  $access_token = $secret-&gt;access_token;
  
  
  $post = array(
  'title'=&gt;'Hello World',
  'content'=&gt;'Hello. I am a test post. I was created by
  the API',
  'date'=&gt;date('YmdHis'),
  'categories'=&gt;'API','tags=tests'
  );
  $post = http_build_query($post);
  $apicall = "https://public-api.wordpress.com/rest/v1/sites/mysite.wordpress.com/posts/new";
  $ch = curl_init($apicall);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array
  ('authorization: Bearer ' . $access_token,"Content-Type: application/x-www-form-urlencoded;
  charset=utf-8"));
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  curl_setopt($ch, CURLOPT_VERBOSE, 1); 
  $return = curl_exec($ch);
  echo "&lt;pre&gt;";
  print_r($return);
  exit;
  
  ?&gt;
  </code></pre>
  
  <p>but I get this error:</p>
  
  <blockquote>
    <p>{"error":"unauthorized","message":"User cannot publish posts"}</p>
  </blockquote>
  
  <p>Can help me?</p>
  
  <p>Thanks</p>