python - GMAIL API:new_request() 最多接受 1 个位置参数(给定 2 个)
问题描述
我正在使用 gmail api。我收到以下警告:
new_request() 最多接受 1 个位置参数(给定 2 个)
从此代码:
message = GMAIL.users().messages().get(userId=user_id, id=m_id).execute() # fetch the message using API
这是我的完整代码(主要取自 gmail API):
"""
Shows basic usage of the Gmail API.
Lists the user's Gmail labels.
"""
from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run_flow, argparser
from oauth2client import tools
from colorama import Fore, Back, Style
from colorama import init
# use Colorama to make Termcolor work on Windows too
init()
# Setup the Gmail API
def get_credentials():
store = file.Storage('credentials.json')
creds = store.get()
flow = OAuth2WebServerFlow(
client_id='845-ehe.apps.googleusercontent.com',
client_secret='curo',
scope = 'https://www.googleapis.com/auth/gmail.modify',
user_agent='people_cal2sms')
if not creds or creds.invalid:
flags = tools.argparser.parse_args(args=[])
creds = tools.run_flow(flow, store, flags)
service = build('gmail', 'v1', http=creds.authorize(Http()))
# Importing required libraries
from apiclient import discovery
# Creating a storage.JSON file with authentication details
SCOPES = 'https://www.googleapis.com/auth/gmail.modify' # we are using modify and not readonly, as we will be marking the messages Read
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
flags = tools.argparser.parse_args(args=[])
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store, flags)
GMAIL = discovery.build('gmail', 'v1', http=creds.authorize(Http()))
user_id = 'me'
label_id_one = 'INBOX'
# Getting all the unread messages from Inbox
# labelIds can be changed accordingly
unread_msgs = GMAIL.users().messages().list(userId='me',labelIds=[label_id_one], q="label:clinic_sms after:2018/9/14").execute()
# We get a dictonary. Now reading values for the key 'messages'
mssg_list = unread_msgs.get('messages', [])
print ("Total unread messages in inbox: ", str(len(mssg_list)))
final_message_dict_list = [ ]
def retrieve_phone_2_gmail_message_dict():
phone_2_gmail_message_dict = {}
for mssg in mssg_list:
message_dict = { }
m_id = mssg['id'] # get id of individual message
message = GMAIL.users().messages().get(userId=user_id, id=m_id).execute() # fetch the message using API
解决方案
推荐阅读
- r - 在 Shiny 中使用 selectInput 从 API 过滤数据
- angular - Angular 6 中的服务测试 - mockBackend
- python - 如何在 Pyspark 中保持其余数据框相同的同时转换一列数据框?
- excel - 对评估和格式化的单元格进行条件检查
- java - Tomcat 9 无效的密钥库密码
- web-scraping - Global ItemLoader - 在多个蜘蛛之间共享
- linker - 在 AIX 上链接 Autotools 项目时避免使用 -blibpath
- java - Vars 通过 runOnUiThread (Android) 变为空
- node.js - 如何在保持对请求对象的访问的同时对 express-graphql 解析器进行依赖注入?
- hp-uft - 如何使用 HP UFT 循环浏览 webtable 并打印第 1 列和第 2 列中每一行的文本