def authorized_http(credentials): """Returns an http client that is authorized with the given credentials. Args: credentials (Union[ google.auth.credentials.Credentials, oauth2client.client.Credentials]): The credentials to use. Returns: Union[httplib2.Http, google_auth_httplib2.AuthorizedHttp]: An authorized http client. """ from googleapiclient.http import build_http if HAS_GOOGLE_AUTH and isinstance( credentials, google.auth.credentials.Credentials): if google_auth_httplib2 is None: raise ValueError( 'Credentials from google.auth specified, but ' 'google-api-python-client is unable to use these credentials ' 'unless google-auth-httplib2 is installed. Please install ' 'google-auth-httplib2.') return google_auth_httplib2.AuthorizedHttp(credentials, http=build_http()) else: return credentials.authorize(build_http())
def authorized_http(credentials): """Returns an http client that is authorized with the given credentials. Args: credentials (Union[ google.auth.credentials.Credentials, oauth2client.client.Credentials]): The credentials to use. Returns: Union[httplib2.Http, google_auth_httplib2.AuthorizedHttp]: An authorized http client. """ from googleapiclient.http import build_http if HAS_GOOGLE_AUTH and isinstance( credentials, google.auth.credentials.Credentials): if google_auth_httplib2 is None: raise ValueError( 'Credentials from google.auth specified, but ' 'google-api-python-client is unable to use these credentials ' 'unless google-auth-httplib2 is installed. Please install ' 'google-auth-httplib2.') return google_auth_httplib2.AuthorizedHttp(credentials, http=build_http()) else: return credentials.authorize(build_http())
def authorized_http(credentials, default_http=None): """Returns an http client that is authorized with the given credentials. Args: credentials (Union[ google.auth.credentials.Credentials, oauth2client.client.Credentials]): The credentials to use. default_http (Union[httplib2.Http, None]): A httplib2.Http object which will be used to make http requests. Returns: Union[httplib2.Http, google_auth_httplib2.AuthorizedHttp]: An authorized http client. """ http = default_http if not http: from googleapiclient.http import build_http http = build_http() if HAS_GOOGLE_AUTH and isinstance(credentials, google.auth.credentials.Credentials): if google_auth_httplib2 is None: raise ValueError( 'Credentials from google.auth specified, but ' 'google-api-python-client is unable to use these credentials ' 'unless google-auth-httplib2 is installed. Please install ' 'google-auth-httplib2.') return google_auth_httplib2.AuthorizedHttp(credentials, http=http) else: return credentials.authorize(http)
def authorized_http(credentials): """Returns an http client that is authorized with the given credentials. Args: credentials (Union[ google.auth.credentials.Credentials, oauth2client.client.Credentials]): The credentials to use. Returns: Union[httplib2.Http, google_auth_httplib2.AuthorizedHttp]: An authorized http client. """ if HAS_GOOGLE_AUTH and isinstance(credentials, google.auth.credentials.Credentials): return google_auth_httplib2.AuthorizedHttp(credentials) else: return credentials.authorize(httplib2.Http())
def authorized_http(credentials): """Returns an http client that is authorized with the given credentials. Args: credentials (Union[ google.auth.credentials.Credentials, oauth2client.client.Credentials]): The credentials to use. Returns: Union[httplib2.Http, google_auth_httplib2.AuthorizedHttp]: An authorized http client. """ if HAS_GOOGLE_AUTH and isinstance( credentials, google.auth.credentials.Credentials): return google_auth_httplib2.AuthorizedHttp(credentials) else: return credentials.authorize(httplib2.Http())