Using python to make authentication into GMail API.

Is simple to do with python. The script I make is simple without classes.
Let’s start with the first steps:
You need to create your project and then one credential with a json file.
See the next image to see how is your JSON file. My JSON file is renamed to client_secret.json and is used by a python script.
python-oauth2
The JSON file is into the same folder with my python script.
After the first run, the script will make one json file named: gmail-python-quickstart.json.
Is a simple way to get and put credentials to solve authentification to google.
Another step is to add the GMail API library to your project. This allows you to use the functions from the Gmail API.
The python script is very simple to do. Follow the part of this script.
Is need to use some python modules. One reason is to deal with email format, see email python module.
Some python modules are used to make authentication to google: oauth2client and apiclient.
I used argparse python module but is no need to add arguments to the script.
The result of this script will send an email to your@yahoo.com.
The email is created by CreateMessage function.
About the special value “me” that comes from Google API and is for the user.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.