【问题标题】:How can I post google blooger without a limit?如何无限制地发布谷歌博客?
【发布时间】:2021-11-20 11:52:04
【问题描述】:

我是一个谷歌博客。 我每天使用 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()

你知道有什么方法不用手动刷新凭证吗?

【问题讨论】:

  • 您在 credentials.storage 文件中看到了什么?有刷新令牌吗?您在谷歌云控制台上的项目是否设置为测试?

标签: python oauth limit blogs credentials


【解决方案1】:

我的 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-10
    • 1970-01-01
    • 1970-01-01
    • 2017-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-14
    相关资源
    最近更新 更多