Google Service
This is the full description of the GoogleService class
GoogleService class
- class google_workspace.service.GoogleService
GoogleService, A supercharged google service.
- Parameters
api (
str
) – The service api e.g. ‘gmail’.session (
str
|dict
, optional) – Pass a string of your choice to give a name to the client session, e.g.: “gmail”. This name will be used to save a file on disk that stores details needed to reconnect without asking again for credentials. If you don’t pass a value the credentials will not be writen to disk, so in order to preserve the credentials you can use the export_session method which will return a dict which you can save however you want, and then use it as the value here in order to reconnect. Defaults to None.client_secrets (
str
, optional) – A file path to the secrets file, or the secrets as a dict. you only need this when connecting for the first time. Defaults to “creds.json”.scopes (
str
|list
, optional) – The scopes you want to authenticate you only need this when connecting for the first time. Defaults to None.version (
str
, optional) – The api version, if you don’t specify we will default to the latest one. Defaults to None.api_key (
str
, optional) – Your api key (if you are not using oauth). Defaults to None.http (
Http
, optional) – Optionally use diffrent http instance when usingapi_key
. Defaults to None.service (
Resource
, optional) – Use your own constructedResource
object. Defaults to None.credentials (
Credentials
, optional) – Use your own constructedCredentials
object. Defaults to None.workdir (
str
, optional) – Where to store the session files and where to look for the creds file. Defaults to None.
- version
A string of the api version.
- api
A string of the api.
- workdir
A Path object of the working directory.
- session_file
A string of the session file if session was a string.
- session_data
A dict of the session data, including the token and addtional values set by set_value().
- is_authenticated
A boolean indicating if the service is authenticated.
- close() None
Closes the open http connection.
- code_oauth() str
Runs a flow to authenticate a user remotely by a code.
- Returns
The url for the user to authenticate.
- Return type
str
- delete() None
Deletes the session file, and revokes the token.
- export_session() dict
Export the session data, updating the token first.
- Returns
The session data.
- Return type
dict
- fetch_token(code: Optional[str] = None, authorization_response: Optional[str] = None, state: Optional[str] = None)
Complete the authentiction process.
- Parameters
code (
str
, optional) – The code that the user got from google when they authorized your app. Defaults to None.authorization_response (
str
, optional) – The reponse that the client sent to your server after the user authorized your app. Defaults to None.state (
str
, optional) – The state used when you started the flow. Defaults to None.
- Returns
Authenticated GoogleService.
- Return type
- get_auth_url(state: Optional[str] = None) str
Get a url with redirect_url taken from self.redirect_uri, you can use this if you are running the server yourself. When you get the code or authorization_response from the user, you can use fetch_token to complete the authentication process.
- Parameters
state (
str
, optional) – Set the state for the authentication flow.- Returns
The url for the user to authenticate.
- Return type
str
- get_state()
Get the state for the current flow.
- Returns
If you started a flow it will return the state, otherwise it will return None.
- Return type
str
- get_value(key: str) Any
Get a value from the service set by set_value.
- Parameters
key (str) – The key.
- Returns
The value.
- Return type
Any
- local_oauth(server_port: int = 2626) None
Run a local server to authenticate a user.
- Parameters
server_port (
int
, optional) – The port to run the server on. Defaults to 2626.
- make_thread_safe() None
Set’s this service to be thread safe. Used internally.
- set_value(key: str, value: Any) None
Set a value for the service.
- Parameters
key (
str
) – The key.value (
Any
) – the value.
- url_oauth(server_host: str, server_port: Optional[int] = None, success_message: str = 'success', keyfile: Optional[str] = None, certfile: Optional[str] = None, block=False) str
Runs a flow to authenticate a user remotely by a url.
- Parameters
server_host (
str
) – The host name of the machine (no http:// etc.).server_port (
int
, optional) – The port to run the server on, if not provided we will look into the client_secrets file to determine which ports you have setup in your redirect_uris, this will only work if the file is updated after changing the settings in the google cloud console. Defaults to None.success_message (
str
, optional) – A message to display to the user after they successfully authenticated. Defaults to “success”.keyfile (
str
, optional) – Your ssl keyfile to enable ssl for the server that we are going to run. Defaults to None.certfile (
str
, optional) – Your ssl certfile to enable ssl for the server that we are going to run. Defaults to None.block (
bool
, optional) – whether to have to program wait for the user to enter the link and finnish the signup, or move on with the execution of the program. Defaults to False.
- Returns
If
block
is set to False (default) the function will return the url, otherwise we print the url.- Return type
str
|None