hi all, I am new to python and trying to replace the client.ClientLogin call that we used to make to google analytics before it was deprecated. the version the python that I am using is 2.6.4. I have done research on line find a suggestion to use OAuth authentication protocol. below is how I used to get access to google analytics API.
this was working before ClientLogin was deprecated April 20, 2015
import os, sys, commands, getopt
import datetime
import random
import time
import gdata.analytics.client
client = gdata.analytics.client.AnalyticsClient()
client.ClientLogin( GOOGA_USER , GOOGA_PASSWD , GOOGA_SCOPE )
this is what I am trying now and it is not working:
import os, sys, commands, getopt
import datetime
import random
import time
import gdata.analytics.client
import gdata.gauth
value for GOOGA_SCOPE should “never” change
GOOGA_SCOPE = ‘https://www.google.com/analytics/feeds/’
I have already created client_id and client_secret on google console
CLIENT_ID = ‘dgdgdgdgdggdgd.com’
CLIENT_SECRET = ‘hahhhhhhhhhhhhhhhh’
USER_AGENT=‘analytics’
token = gdata.gauth.OAuth2Token(client_id=CLIENT_ID,client_secret=CLIENT_SECRET,scope=GOOGA_SCOPE,user_agent=USER_AGENT)
url = token.generate_authorize_url(redirect_uri=‘urn:ietf:wg:oauth:2.0:oob’)
code = url – what is the best way to get the code out of the above URL?
token.get_access_token(code) – Statement is always failing. can someone help me figure it out what I am doing wrong?