title: Cannot create or update posts using php v3 library ((403) We're sorry, but you don't have permission to access this resource.')
body: <p>I use the Blogger library v3 for php,I can not insert a new post. </p>
  
  <p>The error message was:</p>
  
  <pre><code>Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling POST https://www.googleapis.com/blogger/v3/blogs/3631076204866601722/posts: (403) We're sorry, but you don't have permission to access this resource.' in E:\xampp\htdocs\Udemy2Blogger\libs\Google\Http\REST.php:79
  Stack trace:
   #0 E:\xampp\htdocs\Udemy2Blogger\libs\Google\Http\REST.php(44): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request))
   #1 E:\xampp\htdocs\Udemy2Blogger\libs\Google\Client.php(508): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request))
   #2 E:\xampp\htdocs\Udemy2Blogger\libs\Google\Service\Resource.php(195): Google_Client-&gt;execute(Object(Google_Http_Request))
   #3 E:\xampp\htdocs\Udemy2Blogger\libs\Google\Service\Blogger.php(1495): Google_Service_Resource-&gt;call('insert', Array, 'Google_Service_...')
   #4 E:\xampp\htdocs\Udemy2Blogger\index.php(78): Google_Service_Blogger_Posts_Resource-&gt;insert('363107620486660...', Object(Google_Service_Blogger_Post), Array)
   #5 {main} thrown inE:\xampp\htdocs\Udemy2Blogger\libs\Google\Http\REST.php on line 79
  </code></pre>
  
  <p>the code is:</p>
  
  <pre><code>&lt;?php
  
  session_start();
  $path = "libs";
  set_include_path(get_include_path() . PATH_SEPARATOR . $path);
  
  require_once 'Google/Client.php';
  require_once 'Google/Service/Blogger.php';
  
  $blogId = 'xxxxxxxxxxxxxxxxxxxx';
  
  $service_account_name = 'xxxxxxxxxxxxxxxxxxxx';
  $key_file_location = 'udemy coupon free-e0de16bee449.p12';
  
  $client = new Google_Client();
  $client-&gt;setAccessType('offline');
  $client-&gt;setApplicationName("Udemy coupon free");
  
  $bloggerService = new Google_Service_Blogger($client);
  
  /************************************************
    If we have an access token, we can carry on.
    Otherwise, we'll get one with the help of an
    assertion credential. In other examples the list
    of scopes was managed by the Client, but here
    we have to list them manually. We also supply
    the service account
   ************************************************/
  if (isset($_SESSION['service_token'])) {
    $client-&gt;setAccessToken($_SESSION['service_token']);
  }
  $key1 = file_get_contents($key_file_location);
  $cred = new Google_Auth_AssertionCredentials(
      $service_account_name,
      array('https://www.googleapis.com/auth/blogger'),
      $key1
  );
  
  $client-&gt;setAssertionCredentials($cred);
  if($client-&gt;getAuth()-&gt;isAccessTokenExpired()) {
    $client-&gt;getAuth()-&gt;refreshTokenWithAssertion($cred);
  }
  
  $_SESSION['service_token'] = $client-&gt;getAccessToken();
  $newpost = new Google_Service_Blogger_Post();
  $newpost-&gt;setTitle("test");
  $newpost-&gt;setContent("test content");
  
  $post = $bloggerService-&gt;posts-&gt;insert($blogId, $newpost, array());
  
  
  print_r($post);
  </code></pre>
  
  <p>Enable Blogger Api v3:</p>
  
  <p><img src="https://i.stack.imgur.com/xjVpG.png" alt="Enable Blogger Api v3"></p>
  
  <p>Create client id (service account):</p>
  
  <p><img src="https://i.stack.imgur.com/kw3mX.png" alt="Create client id (service account) 1"></p>
  
  <p><img src="https://i.stack.imgur.com/8kPp4.png" alt="Create client id (service account) 2"></p>
  
  <p>Please help me, thanks a lot!</p>