Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 run_flow抱怨至少得到了三个参数_Python 2.7_Google Oauth_Google Api Python Client_Gmail Api - Fatal编程技术网

Python 2.7 run_flow抱怨至少得到了三个参数

Python 2.7 run_flow抱怨至少得到了三个参数,python-2.7,google-oauth,google-api-python-client,gmail-api,Python 2.7,Google Oauth,Google Api Python Client,Gmail Api,我正在编写一个通过GMail API发送电子邮件的简单脚本,但我发现一个访问他们SMTP接口的旧脚本不起作用 因此,我首先从阅读开始使用了他们的以下脚本: #! /usr/bin/env python #

我正在编写一个通过GMail API发送电子邮件的简单脚本,但我发现一个访问他们SMTP接口的旧脚本不起作用

因此,我首先从阅读开始使用了他们的以下脚本:

#! /usr/bin/env python
#
                                                                                                                                                               
import httplib2
                                                                                                                                                               
from apiclient.discovery import build
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.tools import run

CLIENT_SECRET = '.client.json'
OAUTH_SCOPE = 'https://www.googleapis.com/auth/gmail.readonly'
STORAGE = Storage('gmail.storage')
                                                                                                                                                               
flow = flow_from_clientsecrets(CLIENT_SECRET, scope=OAUTH_SCOPE)
http = httplib2.Http()
                                                                                                                                                               
credentials = STORAGE.get()
if credentials is None or credentials.invalid:
    credentials = run(flow, STORAGE, http=http)
                                                                                                                                                                   
http = credentials.authorize(http)
                                                                                                                             
gmail_service = build('gmail', 'v1', http=http)
threads = gmail_service.users().threads().list(userId='me').execute()
                                                                                                                                                                   
if threads['threads']:
    for thread in threads['threads']:
        print 'Thread ID: %s' % (thread['id'])
运行此命令会产生一个
NotImplementedError
,如中所示

因此,我导入并调用了
run\u flow
,而不是
run
,因为我没有安装
gflags
来继续。但是,我得到以下错误:

TypeError: run_flow() takes at least 3 arguments (3 given)
我从链接的问题中了解到,
argparse
应该会有所帮助。我可以添加对该问题使用的
解析器的调用,但我不知道在命令行上传递什么参数


任何人都可以成功地用这个实现一些东西,谁能提供一些帮助?

在使用run\u flow python时,您不需要向命令行传递额外的参数

import argparse
...
from oauth2client import tools
...
from oauth2client.tools import run_flow
...
parser = argparse.ArgumentParser(parents=[tools.argparser])
flags = parser.parse_args()
....
credentials = run_flow(flow, STORAGE, flags, http=http)
然后你就可以跑了

python quickstart.py

不确定“他们已经禁用了SMTP接口”是什么意思,但我向您保证,谷歌并没有禁用他们的SMTP接口嗯,哎哟,当我写到:P我想我的意思是说一个使用libsmtp连接到谷歌的旧Python脚本不再工作了p这导致我在登录后出现400个错误,但至少这是一个进步。看起来我需要匹配
重定向uri
s。谢谢