How to login into an website which is authenticated by google + API using python?
<p>How to get logged into some website using python code
<code>i.e www.example.com/auth/gmail</code> which is taking advantage of google+ API for user logins. Now I would like to login with my credentials (Gmail or What?) by using python code. Please help me how to approach towards this problem.</p>

<p>Thanks</p>

<p>Here you have an example by using the google-api-python-client
First of all you have to create your client secrets on the google developer console.</p>

<p>First time you execute the code you will have to authorize the script to use your gmail account, then you can save the credentials on a file as on the example, and use it for the future executions without requiring this authentication</p>

<pre><code>from googleapiclient.discovery import build
from oauth2client import client
from googleapiclient.errors import HttpError
import base64
from email.mime.text import MIMEText
from apiclient import errors
from oauth2client import client
import httplib2
from googleapiclient.discovery import build


def getCredentials(secrets, scope,filename):
    flow = client.flow_from_clientsecrets(
            secrets,
            scope=scope,
            redirect_uri='urn:ietf:wg:oauth:2.0:oob')
    auth_uri = flow.step1_get_authorize_url()
    webbrowser.open(auth_uri)
    auth_code = raw_input('Enter the auth code: ')
    credentials = flow.step2_exchange(auth_code)
    saveJson(filename,credentials.to_json())


def saveJson(filename, object):
    with open(filename, 'w') as f:
        json.dump(object, f)

def openJson(filename):
    with open(filename, 'r') as f:
        object = json.load(f)
    return object

if __name__=='__main__':
    client_secrets = 'client_secrets.json' #client secrets to use the API
    credentials = 'auth_credentials.json'
    if(firstRun) #create a file with the auth credentials
        scope = 'https://www.googleapis.com/auth/gemail.send'
        getCredentials(secrets,scope,credentials)

    cre = client.Credentials.new_from_json(openJson(credentials))
    http_auth = cre.authorize(httplib2.Http())
    gmail = build('gmail', 'v1', http=http_auth)
    #gmail.doSomething
</code></pre>

python google-api google-api-python-client