为什么gmail python客户端没有读取我的json文件?

时间:2014-11-13 15:06:13

标签: python file api oauth gmail

让用户使用OAuth对我的应用进行身份验证后,我想扫描用户的Gmail以获取特定附件并对这些附件进行操作。我设法让用户为gmail readonly scopehttps://www.googleapis.com/auth/gmail.readonly)验证我的应用(OAuth2),但我似乎无法获得连接到api工作的示例代码。

根据this page,GMail API的典型用例是" 只读邮件提取,索引和备份" (正是我想要的)。由于我在Python工作,我安装了Gmail API client lib for Python,我现在想用它来获取消息列表。

所以我尝试使用this Python example code创建第一个连接。我保存了' client_secret.json'与' quickstart.py'相同的文件夹示例代码,然后我运行代码。不幸的是,它似乎找不到文件client_secret.json。我遇到麻烦的代码是:

CLIENT_SECRET_FILE = 'client_secret.json'
OAUTH_SCOPE = 'https://www.googleapis.com/auth/gmail.readonly'
STORAGE = Storage('gmail.storage')
flow = flow_from_clientsecrets(CLIENT_SECRET_FILE, scope=OAUTH_SCOPE)
http = httplib2.Http()
credentials = STORAGE.get()
print credentials is None  # Prints out True
if credentials is None or credentials.invalid:  # so credentials turns out to be None
    credentials = run(flow, STORAGE, http=http)

我将json文件chmod到777,100%确定它在同一个文件夹中,甚至尝试提供json文件的绝对路径,但无济于事。有谁知道为什么gmail google-api-python-client找不到我的json文件?欢迎所有提示!

0 个答案:

没有答案