title: How to get a list of most popular pages from Google Analytics in Python (Django)?
body: <p>I'm trying to access Google Analytics API using the code provided by their documentation: <a href="https://developers.google.com/analytics/solutions/articles/hello-analytics-api">https://developers.google.com/analytics/solutions/articles/hello-analytics-api</a></p>
  
  <pre><code>import httplib2
  import os
  
  from apiclient.discovery import build
  from oauth2client.client import flow_from_clientsecrets
  from oauth2client.file import Storage
  from oauth2client.tools import run
  
  
  CLIENT_SECRETS = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'client_secrets.json')
  MISSING_CLIENT_SECRETS_MESSAGE = '%s is missing' % CLIENT_SECRETS
  FLOW = flow_from_clientsecrets('%s' % CLIENT_SECRETS,
      scope='https://www.googleapis.com/auth/analytics.readonly',
      message=MISSING_CLIENT_SECRETS_MESSAGE,
  )
  TOKEN_FILE_NAME = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'analytics.dat')
  
  
  def prepare_credentials():
      storage = Storage(TOKEN_FILE_NAME)
      credentials = storage.get()
  
      if credentials is None or credentials.invalid:
          credentials = run(FLOW, storage)
  
      return credentials
  
  
  def initialize_service():
      http = httplib2.Http()
      credentials = prepare_credentials()
      http = credentials.authorize(http)
  
      return build('analytics', 'v3', http=http)
  
  
  def get_analytics():
     initialize_service()
  </code></pre>
  
  <p>But the problem is that this code opens a browser and asks a user to allow access to analytics service. Does anyone know how to access Google Analytics API (=obtain that token) without oauth2?</p>