python - 谷歌博客 API : AccessTokenRefreshError:invalid_grand message

标签 python blogger google-data-api google-api-python-client

我正在使用 google-python-client-api 作为 Blogger API(服务帐户 - OAuth)。

这是我的代码(取 self 的任务 api example )

import httplib2
import pprint
import sys

from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials

f = file("privatekey.p12", "rb")
key = f.read()
f.close()

credentials = SignedJwtAssertionCredentials(
    "2-abcdr@developer.gserviceaccount.com",
    key,
    scope = "https://www.googleapis.com/auth/blogger")

http = httplib2.Http()
http = credentials.authorize(http)

service = build("blogger", "v3", http=http)

当我运行此代码时,它显示

Message File Name   Line    Position    
Traceback               
    <module>    D:\Code\myScripts\py\gData.py   20      
    build   build\bdist.win32\egg\apiclient\discovery.py    191     
    new_request build\bdist.win32\egg\oauth2client\client.py    402     
    _refresh    build\bdist.win32\egg\oauth2client\client.py    569     
    _do_refresh_request build\bdist.win32\egg\oauth2client\client.py    625     
AccessTokenRefreshError: invalid_grant      

问题是什么?我应该如何解决?

我什至尝试了tasks.py示例代码..甚至显示了相同的错误

我非常确定服务帐户电子邮件地址是正确的

最佳答案

我在查询 BigQuery 时遇到了类似的问题。从互联网上存在的少量文档来看,这似乎是分辨率差的时钟导致计时错误导致 SignedJWTCredentials 无效的问题。一种建议的解决方案是确保时钟的计时器与 ntp 同步。由于我要部署到 Heroku,因此我的解决方案是优雅地失败,然后重试。

另请参阅https://code.google.com/p/google-api-php-client/wiki/OAuth2#Solving_invalid_grant_errors

关于python - 谷歌博客 API : AccessTokenRefreshError:invalid_grand message,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11582357/

相关文章:

python - 无法修复 "zipimport.ZipImportError: can' t 解压数据; zlib 不可用”当我输入 "python3.6 get-pip.py"

javascript - 如何为 Blogger 添加国际化支持?

html - 水平对齐div中的3个按钮

flutter - 如何在Flutter中重新格式化Blogger API中的数据

python - 使用 str.contains 时有没有办法排除特定子字符串?

Python - 将列表转换为列表列表,每个条目包含唯一组合

python - 使用 gdata-python-client 下载 Google 站点页面内容提要

c# - 由于 Google 数据列表 API 已被弃用,那么 Google 网站应使用哪个 API?

python - Google 电子表格 API 列标题

python - 使用 matplotlib 进行 PCA 的基本示例