当前位置: 首页>>代码示例>>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;未经允许,请勿转载。