问题
I want to insert a post to my blog by php in my server cron so there there is no any manual login.
I have create Service Account and can get the post by $data = $blogger->posts->get('6284611449262742568', '4655425391398964038');
However, insert post fail with following error.
data = $blogger->posts->insert('6284611449262742568', $mypost);
Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling POST https://www.googleapis.com/blogger/v3/blogs/6284611449262742568/posts: (403) We're sorry, but you don't have permission to access this resource.' in /xx/lab/GoogleClientApi/src/Google/Http/REST.php:110
Stack trace:
#0 /xx/lab/GoogleClientApi/src/Google/Http/REST.php(62): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request), Object(Google_Client))
#1 [internal function]: Google_Http_REST::doExecute(Object(Google_Client), Object(Google_Http_Request))
#2 /xx/lab/GoogleClientApi/src/Google/Task/Runner.php(174): call_user_func_array(Array, Array)
#3 /xx/lab/GoogleClientApi/src/Google/Http/REST.php(46): Google_Task_Runner->run()
#4 /xx/lab/GoogleClientApi/src/Google/Client.php(563): Google_Http_REST::execute(Object(Goog in /xx/lab/GoogleClientApi/src/Google/Http/REST.php on line 110
How can I have the permission to insert/modify post to my blog?
回答1:
Service accounts are not supported with Blogger. Blogger requires people using Blogger to agree to our Terms of Service, and Service Accounts can't accept them.
A work around would be to use Normal Oauth2 Authentication. Authentication your code once save the refresh token and use that in your cron script.
来源:https://stackoverflow.com/questions/29119637/how-to-insert-post-to-my-blog-in-server-by-service-account-without-any-manual-lo