Я использую API Gmail.Я получаю следующее предупреждение:
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