python - 如何无限制地发布谷歌博客?
问题描述
我是一个谷歌博客。我每天使用 python 上传 10 个帖子。上传了 25 个帖子后,我必须制作一个新的凭据。
这是代码
CLIENT_SECRET = 'client_secret.json'
SCOPE = 'https://www.googleapis.com/auth/blogger'
STORAGE = Storage('credentials.storage')
# Start the OAuth flow to retrieve credentials
def authorize_credentials():
# Fetch credentials from storage
credentials = STORAGE.get()
# If the credentials doesn't exist in the storage location then run the flow
if credentials is None or credentials.invalid:
flow = flow_from_clientsecrets(CLIENT_SECRET, scope=SCOPE)
http = httplib2.Http()
credentials = run_flow(flow, STORAGE, http=http)
return credentials
credentials = authorize_credentials()
您是否知道有任何方法无需手动刷新凭证?
解决方案
我的 python 不是最好的,但我认为你可能有缩进问题。看看这个。
def initialize_blogger():
"""Initializes the blogger service object.
Returns:
analytics an authorized blogger service object.
"""
# Parse command-line arguments.
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
parents=[tools.argparser])
flags = parser.parse_args([])
# Set up a Flow object to be used if we need to authenticate.
flow = client.flow_from_clientsecrets(
CLIENT_SECRETS_PATH, scope=SCOPES,
message=tools.message_if_missing(CLIENT_SECRETS_PATH))
# Prepare credentials, and authorize HTTP object with them.
# If the credentials don't exist or are invalid run through the native client
# flow. The Storage object will ensure that if successful the good
# credentials will get written back to a file.
storage = file.Storage('blogger.dat')
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = tools.run_flow(flow, storage, flags)
http = credentials.authorize(http=httplib2.Http())
# Build the service object.
service= build('blogger', 'v3', http=http)
return service
推荐阅读
- jquery - 数据表搜索字段始终聚焦停止所有其他操作
- jquery - 剑道甘特图与剑道调度器
- dart - Why FutureBuilder doesn't get call in Flutter?
- cordova - 我们可以使用此 cordova 插件在推送通知中发送图像:用于移动应用程序的 cordova-plugin-fcm 吗?
- abap - 如何在内部表中生成新的自己的列表?abap
- sql-server - SQL REPORTING 服务 (SSRS) 无法启动 - 删除并重新安装
- ios - 后端使用 URLSession.shared.dataTask 为 post 方法接收错误数据
- workflow - 外部用户如何在不创建 APS 帐户的情况下访问 APS(Alfresco 流程服务)?
- ruby-on-rails - 在 Rails 中将多个输入字段作为列表发布,而不是单独的名称。
- react-native - 这可以改进吗?