Exemplo n.º 1
0
    def locked_get(self):
        """Original:Retrieve Credential from file.
           !!!
           Subclassed and Overrided: Retrieve Credential from ENCRYPTED file
           !!!

        Returns:
          oauth2client.client.Credentials

        Raises:
          CredentialsFileSymbolicLinkError if the file is a symbolic link.
        """
        credentials = None
        self._validate_file()
        try:
            f = open(self._filename, 'rb')
            content = self.enc.decrypt(self._key, f.read())
            f.close()
        except IOError:
            return credentials

        try:
            credentials = Credentials.new_from_json(content)
            credentials.set_store(self)
        except ValueError:
            pass

        return credentials
Exemplo n.º 2
0
def initialize_service(googleanalytics_auth_json):
  # Create an httplib2.Http object to handle our HTTP requests.
  http = httplib2.Http()
  # Prepare credentials, and authorize HTTP object with them.
  assert googleanalytics_auth_json,'No GOOGLEANALYTICS_AUTH set in environment. This should be the sample.dat file created by authenticating a sample app with Google Analytics.\n\n  Read: https://developers.google.com/analytics/solutions/articles/hello-analytics-api'
  credentials = Credentials.new_from_json(googleanalytics_auth_json)
  if credentials is None or credentials.invalid:
    credentials = run(FLOW, storage)
  http = credentials.authorize(http)
  # Retrieve service.
  return build('analytics', 'v3', http=http)