如何通过服务帐户将帖子插入服务器中的博客,而无需任何手动登录 [英] how to insert post to my blog in server by Service Account without any manual login

查看:51
本文介绍了如何通过服务帐户将帖子插入服务器中的博客,而无需任何手动登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在服务器cron中通过php在我的博客中插入帖子,因此没有任何手动登录. 我已经创建了服务帐户,可以通过$data = $blogger->posts->get('6284611449262742568', '4655425391398964038');来获取信息 但是,插入帖子失败,并出现以下错误. data = $blogger->posts->insert('6284611449262742568', $mypost);

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

致命错误:未捕获的异常"Google_Service_Exception"与 消息调用POST时出错 https://www.googleapis.com/blogger/v3/blogs/6284611449262742568/posts : (403)很抱歉,您无权访问此文件 资源."在/xx/lab/GoogleClientApi/src/Google/Http/REST.php:110

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

堆栈跟踪:

#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?

推荐答案

Blogger不支持服务帐户. Blogger要求使用Blogger的人同意我们的服务条款,而服务帐户则不能接受.

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.

一种解决方法是使用普通Oauth2身份验证.验证您的代码后,将保存刷新令牌并在您的cron脚本中使用它.

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.

这篇关于如何通过服务帐户将帖子插入服务器中的博客,而无需任何手动登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆