Logging into google plus with google account in python
<p>I want to be able to use urllib2.urlopen() or requests.get() with <a href="http://plus.google.com/" rel="nofollow">http://plus.google.com/</a>* url's.</p>

<p>Using python, how would I go about doing that? I need to login first, but how?</p>

<p>The following code returns something along the lines of:</p>

<pre><code>"Your browser's cookie functionality is turned off. Please turn it on."
</code></pre>

<p>Well, the cookie itself is created and, and I tested robots.txt, there are no diallows... I also tried switching user agents, no luck.</p>

<pre><code>    cookie_filename =  "google.cookie"
    email = raw_input("Enter your Google username: ")
    password = getpass.getpass("Enter your password: ")

    self.cj = cookielib.MozillaCookieJar(cookie_filename)
    self.cj.load()

    self.opener = urllib2.build_opener(
        urllib2.HTTPRedirectHandler(),
        urllib2.HTTPHandler(debuglevel = 0),
        urllib2.HTTPSHandler(debuglevel = 0),
        urllib2.HTTPCookieProcessor(self.cj)
    )

    urllib2.install_opener(self.opener)

    login_page_url = 'https://www.google.com/accounts/ServiceLogin?passive=true&amp;service=grandcentral'
    authenticate_url = 'https://www.google.com/accounts/ServiceLoginAuth?service=grandcentral'
    gv_home_page_url = 'https://www.google.com/voice/#inbox'

    # Load sign in page
    login_page_contents = self.opener.open(login_page_url).read()

    # Find GALX value
    galx_match_obj = re.search(r'name="GALX"\s*value="([^"]+)"', login_page_contents, re.IGNORECASE)       
    galx_value = galx_match_obj.group(1) if galx_match_obj.group(1) is not None else ''

    # Set up login credentials
    login_params = urllib.urlencode( {
       'Email' : email,
       'Passwd' : password,
       'continue' : 'https://www.google.com/voice/account/signin',
       'GALX': galx_value
    })

    # Login
    resp = self.opener.open(authenticate_url, login_params).readlines()
    print resp
    self.opener.open(authenticate_url, login_params).readlines()

    self.cj.save()
    # Open GV home page
    gv_home_page_contents = self.opener.open(gv_home_page_url).read()
    print gv_home_page_contents
</code></pre>
