【发布时间】:2017-06-05 12:46:45
【问题描述】:
我刚刚开始使用 Gmail API,并按照 Oauth2.0 教程获取授权代码。到目前为止我的代码是:
from oauth2client import client
import webbrowser
import httplib2
flow = client.flow_from_clientsecrets(
'client_secrets.json',
scope='https://www.googleapis.com/auth/gmail.readonly',
redirect_uri='urn:ietf:wg:oauth:2.0:oob')
auth_uri = flow.step1_get_authorize_url()
webbrowser.open_new(auth_uri)
authcode = input("Enter auth code: ")
credentials = flow.step2_exchange(authcode)
http_auth = credentials.authorize(httplib2.Http())
我想通过发出请求来测试 API,该请求以这种格式获取最新未读消息的主题和发件人:
#pseudocode
get latestMessage
if latestMessage.read == True:
print("you have no unread messages)
else:
print("you have a new email: " + latestMessage.subject + " from" + latestmessage.sender)
【问题讨论】:
标签: python python-3.x gmail-api