Re: Cannot create or update posts using php v3 library ((403) We're sorry, but you don't have permission to access this resource.')

"'Brett Morgan' via Blogger Developer Group" <[email protected]>
Newsgroups gmane.comp.web.blogger.api
Message-ID <CAAFdGScW2ZqThhBvXJoVNkeOiUyUE6Nj__QCdAfDrPRRNGvqMQ@mail.gmail.com>
I could be wrong, but I don't believe Blogger API supports Service
Accounts.


On Sun, Jul 20, 2014 at 2:46 AM, tien nguyen <[email protected]> wrote:

>
> I use the Blogger library v3 for php,I can not insert a new post.
>
> The error message was:
>
> 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->execute(Object(Google_Http_Request)) #3
> E:\xampp\htdocs\Udemy2Blogger\libs\Google\Service\Blogger.php(1495):
> Google_Service_Resource->call('insert', Array, 'Google_Service_...') #4
> E:\xampp\htdocs\Udemy2Blogger\index.php(78):
> Google_Service_Blogger_Posts_Resource->insert('363107620486660...',
> Object(Google_Service_Blogger_Post), Array) #5 {main} thrown
> inE:\xampp\htdocs\Udemy2Blogger\libs\Google\Http\REST.php on line 79
>
>  the code is:
>  <?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 = '
> 42970721147-m4fcs065rmt3s7qdqqcvnqd1ibt6evlc@developer.gserviceaccount.com
> ';
>
>
> $key_file_location = 'udemy coupon free-e0de16bee449.p12';
>
>
> $client = new Google_Client();
>
> $client->setAccessType('offline');
>
> $client->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->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->setAssertionCredentials($cred);
>
> if($client->getAuth()->isAccessTokenExpired()) {
>
>   $client->getAuth()->refreshTokenWithAssertion($cred);
>
> }
>
>
> $_SESSION['service_token'] = $client->getAccessToken();
>
> $newpost = new Google_Service_Blogger_Post();
>
> $newpost->setTitle("test");
>
> $newpost->setContent("test content");
>
>
> $post = $bloggerService->posts->insert($blogId, $newpost, array());
>
>
>
>
> print_r($post);
>
>
> Enable Blogger Api v3:
>
>
> <https://lh5.googleusercontent.com/-zacEKdSQnOw/U8qeVmlg8HI/AAAAAAAADxE/XPA_-9jgZ4A/s1600/api.png>
>
>
> Create client id (service account):
>
>
> <https://lh3.googleusercontent.com/-A7AYs8TCsAc/U8qgSY1PUkI/AAAAAAAADxc/GXVeJ383Hvw/s1600/service-account.png>
>
>
>
> <https://lh3.googleusercontent.com/-_91m5njWaho/U8qfX9wNKPI/AAAAAAAADxQ/5OZiEKPdt30/s1600/createid.png>
>
>
> Please help me, thanks a lot!
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Blogger Developer Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/bloggerdev.
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Brett Morgan | Developer Relations Engineer, Google Maps |
[email protected] | profiles.google.com/brettmorgan

-- 
You received this message because you are subscribed to the Google Groups "Blogger Developer Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/bloggerdev.
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.