Example #1
0
def return_handle(id_name):
    identity_root = os.path.expanduser(YOUTUBE_DATA_ROOT)
    identity_folder = os.path.join(identity_root, id_name)

    if not os.path.exists(identity_folder):
        n = input("Identity %s is not known; create it? [Y|n] " % id_name)
        if not n or n.lower().startswith('y'):
            create_identity(id_name)
        else:
            sys.exit()
    identity = _retrieve_files(identity_folder)
    c = Credentials().new_from_json(identity['credentials'])
    handle = c.authorize(http=httplib2.Http())

    return googleapiclient.discovery.build(
        "youtube", "v3", http=handle)
Example #2
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
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)