當前位置: 首頁>>代碼示例>>Python>>正文


Python auth.GoogleAuth方法代碼示例

本文整理匯總了Python中pydrive.auth.GoogleAuth方法的典型用法代碼示例。如果您正苦於以下問題:Python auth.GoogleAuth方法的具體用法?Python auth.GoogleAuth怎麽用?Python auth.GoogleAuth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pydrive.auth的用法示例。


在下文中一共展示了auth.GoogleAuth方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: getDrive

# 需要導入模塊: from pydrive import auth [as 別名]
# 或者: from pydrive.auth import GoogleAuth [as 別名]
def getDrive(drive=None, gauth=None):
    if not drive:
        if not gauth:
            gauth = GoogleAuth(settings_file=SETTINGS_YAML)
        # Try to load saved client credentials
        gauth.LoadCredentialsFile(CREDENTIALS)
        if gauth.access_token_expired:
            # Refresh them if expired
            try:
                gauth.Refresh()
            except RefreshError as e:
                log.error("Google Drive error: %s", e)
            except Exception as e:
                log.exception(e)
        else:
            # Initialize the saved creds
            gauth.Authorize()
        # Save the current credentials to a file
        return GoogleDrive(gauth)
    if drive.auth.access_token_expired:
        try:
            drive.auth.Refresh()
        except RefreshError as e:
            log.error("Google Drive error: %s", e)
    return drive 
開發者ID:janeczku,項目名稱:calibre-web,代碼行數:27,代碼來源:gdriveutils.py

示例2: __init__

# 需要導入模塊: from pydrive import auth [as 別名]
# 或者: from pydrive.auth import GoogleAuth [as 別名]
def __init__(self, *args, **kwargs):
        super(GDriveWriter, self).__init__(*args, **kwargs)
        from pydrive.auth import GoogleAuth
        from pydrive.drive import GoogleDrive
        gauth = GoogleAuth()
        files_tmp_path = tempfile.mkdtemp()
        client_secret_file = os.path.join(files_tmp_path, 'secret.json')
        with open(client_secret_file, 'w') as f:
            f.write(json.dumps(self.read_option('client_secret')))
        gauth.LoadClientConfigFile(client_secret_file)
        credentials_file = os.path.join(files_tmp_path, 'credentials.json')
        with open(credentials_file, 'w') as f:
            f.write(json.dumps(self.read_option('credentials')))
        gauth.LoadCredentialsFile(credentials_file)
        shutil.rmtree(files_tmp_path)
        self.drive = GoogleDrive(gauth)
        self.set_metadata('files_counter', Counter())
        self.set_metadata('files_written', []) 
開發者ID:scrapinghub,項目名稱:exporters,代碼行數:20,代碼來源:gdrive_writer.py

示例3: __init__

# 需要導入模塊: from pydrive import auth [as 別名]
# 或者: from pydrive.auth import GoogleAuth [as 別名]
def __init__(self):
        self.auth = GoogleAuth(settings_file=SETTINGS_YAML) 
開發者ID:janeczku,項目名稱:calibre-web,代碼行數:4,代碼來源:gdriveutils.py

示例4: driveAuthorization

# 需要導入模塊: from pydrive import auth [as 別名]
# 或者: from pydrive.auth import GoogleAuth [as 別名]
def driveAuthorization():
    """Authorizes access to the Google Drive"""
    
    gauth = GoogleAuth()
    gauth.LocalWebserverAuth() # Creates local webserver and auto handles authentication.
    drive = GoogleDrive(gauth)
    return drive 
開發者ID:ugroot,項目名稱:GROOT,代碼行數:9,代碼來源:authenticator.py

示例5: get_from_drive

# 需要導入模塊: from pydrive import auth [as 別名]
# 或者: from pydrive.auth import GoogleAuth [as 別名]
def get_from_drive(idv):
  gauth = GoogleAuth()
  gauth.credentials = GoogleCredentials.get_application_default()
  drive = GoogleDrive(gauth)
  last_weight_file = drive.CreateFile({'id': idv}) 
  last_weight_file.GetContentFile('DenseNet-40-12-CIFAR10.h5') 
開發者ID:ambujraj,項目名稱:hacktoberfest2018,代碼行數:8,代碼來源:DenseNet_CIFAR10.py

示例6: authorize_google_drive

# 需要導入模塊: from pydrive import auth [as 別名]
# 或者: from pydrive.auth import GoogleAuth [as 別名]
def authorize_google_drive():
    global GAUTH
    global DRIVE
    if GAUTH is None or DRIVE is None:
        GAUTH = GoogleAuth()
        # Creates local webserver and auto handles authentication.
        GAUTH.LoadClientConfigFile(client_config_file=GRDIVE_CONFIG_PATH)
        GAUTH.LocalWebserverAuth()
        DRIVE = GoogleDrive(GAUTH)
        return True
    else:
        return True 
開發者ID:marl,項目名稱:medleydb,代碼行數:14,代碼來源:download.py

示例7: run

# 需要導入模塊: from pydrive import auth [as 別名]
# 或者: from pydrive.auth import GoogleAuth [as 別名]
def run(args):
    gauth = GoogleAuth()
    gauth.LoadClientConfigFile(args.client_secret)
    gauth.LocalWebserverAuth()
    credentials_file = os.path.join(args.dest, 'gdrive-credentials.json')
    gauth.SaveCredentialsFile(credentials_file)
    print('Credentials file saved to {}'.format(credentials_file)) 
開發者ID:scrapinghub,項目名稱:exporters,代碼行數:9,代碼來源:get_gdrive_credentials.py

示例8: authenticate

# 需要導入模塊: from pydrive import auth [as 別名]
# 或者: from pydrive.auth import GoogleAuth [as 別名]
def authenticate(config):
        logger.debug("GoogleDriveAction starting authentication")
        svc_user_id = config.config_obj.get('GoogleDriveUploadAction', 'service_user_email')
        svc_scope = "https://www.googleapis.com/auth/drive"
        svc_key_file = config.config_obj.get('GoogleDriveUploadAction', 'key_file')
        gcredentials = ServiceAccountCredentials.from_p12_keyfile(svc_user_id, svc_key_file, scopes=svc_scope)
        gcredentials.authorize(httplib2.Http())
        gauth = GoogleAuth()
        gauth.credentials = gcredentials
        logger.debug("GoogleDriveUploadAction authentication complete")
        return gauth 
開發者ID:amdean,項目名稱:motion-notify,代碼行數:13,代碼來源:GoogleDriveActionBase.py

示例9: upload

# 需要導入模塊: from pydrive import auth [as 別名]
# 或者: from pydrive.auth import GoogleAuth [as 別名]
def upload(file_path, description=None):
    try:
        gauth = GoogleAuth()
        # gauth.LocalWebserverAuth()

        # Try to load saved client credentials
        credential_file = os.getenv('GOOGLE_DRIVE_CREDENTIAL_FILE')
        gauth.LoadCredentialsFile(credential_file)
        if gauth.credentials is None:
            # Authenticate if they're not there
            gauth.LocalWebserverAuth()
        elif gauth.access_token_expired:
            # Refresh them if expired
            gauth.Refresh()
        else:
            # Initialize the saved creds
            gauth.Authorize()
        # end if

        # Save the current credentials to a file
        gauth.SaveCredentialsFile(credential_file)

        drive = GoogleDrive(gauth)
        folder_id = os.getenv('GOOGLE_DRIVE_FOLDER_ID')
        filename_w_ext = os.path.basename(file_path)
        filename, file_extension = os.path.splitext(filename_w_ext)

        # Upload file to folder
        f = drive.CreateFile(
            {"parents": [{"kind": "drive#fileLink", "id": folder_id}]})
        f['title'] = filename_w_ext

        # Make sure to add the path to the file to upload below.
        f.SetContentFile(file_path)
        f.Upload()

        logger.info(f['id'])
        return f['id']
    except Exception:
        logger.exception('Failed to upload %s', file_path)
    # end try
    return None
# end def 
開發者ID:dipu-bd,項目名稱:lightnovel-crawler,代碼行數:45,代碼來源:uploader.py


注:本文中的pydrive.auth.GoogleAuth方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。