Reputation: 11
I'm trying to understand and use the example on the Google Developers page for using the Gmail API. The function takes an argument "service", but I am unsure what it expects here.
def SendMessage(service, user_id, message):
Everything else seems self explanatory but I need help on what to provide for the service variable?
The comment given within the example defines "service" as "service: Authorized Gmail API service instance." Which unfortunately still doesn't help me.
I'm not new to Python, but I am new to using APIs.
Upvotes: 1
Views: 1282
Reputation: 143
The argument "service" does get created in the python quickstart example
service = discovery.build('gmail', 'v1', http=http)
That service value can be used in the example you listed in your original question.
Upvotes: 4
Reputation: 1035
The docstring of the function gives us a better idea. Found here
def SendMessage(service, user_id, message):
"""Send an email message.
Args:
service: Authorized Gmail API service instance.
user_id: User's email address. The special value "me"
can be used to indicate the authenticated user.
message: Message to be sent.
Returns:
Sent Message.
"""
If you do not know how get an authorized Gmail API service instance, you can find a pythong quickstart here.
In short, you have to make a call to the API, and you will receive a client.json file, which contains your authentication that you can use in your project.
Upvotes: 2