public class GoogleSheets extends Object
| Constructor and Description |
|---|
GoogleSheets()
Default constructor for GoogleSheets.
|
GoogleSheets(eu.easyrpa.openframework.google.services.GoogleServicesProvider googleServicesProvider)
Constructs GoogleSheets with provided
GoogleServicesProvider. |
| Modifier and Type | Method and Description |
|---|---|
SpreadsheetDocument |
getSpreadsheet(String spreadsheetId)
Gets content of Google spreadsheet file with specified file ID.
|
GoogleSheets |
onAuthorization(eu.easyrpa.openframework.google.services.AuthorizationPerformer authorizationPerformer)
Allows to override the way how this code informs the user that it wishes to act on his behalf and obtain
corresponding access token from Google.
|
GoogleSheets |
secret(String vaultAlias)
Sets explicitly the alias of secret vault entry with OAuth 2.0 Client JSON necessary for authentication on the
Google server.
|
GoogleSheets |
secret(String userId,
String secret)
Sets explicitly the secret OAuth 2.0 Client JSON necessary for authentication on the Google server.
|
public GoogleSheets()
This constructor should be used in case of manual providing of secret information necessary for authorization and instantiation Google Sheets service. E.g.:
String spreadsheetFileId = ...;
String secretJson = new String(Files.readAllBytes(Paths.get("secret.json")), StandardCharsets.UTF_8);
GoogleSheets googleSheets = new GoogleSheets().secret("user1", secretJson);
SpreadsheetDocument doc = googleSheets.getSpreadsheet(spreadsheetFileId);
...
@Inject public GoogleSheets(eu.easyrpa.openframework.google.services.GoogleServicesProvider googleServicesProvider)
GoogleServicesProvider.
This constructor is used in case of injecting of this GoogleSheets using @Inject annotation.
In this case GoogleServicesProvider also will be initialised via injecting of
RPAServicesAccessor that is used for getting of necessary secret information from secret vault of
RPA platform. E.g.:
@Inject
private GoogleSheets googleSheets;
public void execute() {
String spreadsheetFileId = ...;
SpreadsheetDocument doc = googleSheets.getSpreadsheet(spreadsheetFileId);
...
}
googleServicesProvider - instance of GoogleServicesProvider that helps with authorization and
instantiation of Google Sheets service.Injectpublic GoogleSheets onAuthorization(eu.easyrpa.openframework.google.services.AuthorizationPerformer authorizationPerformer)
By default it opens a browser on machine where this code is running and locates to OAuth consent page where user should authorize performing of necessary operations. If this code is running on robot's machine performing of authorization by this way is not possible since user won't able to see the browser page.
Using this method is possible to overrides this behavior and specify, lets say, sending of notification email with link to OAuth consent page to administrator, who is able to perform authorization on behalf of robot's Google account. In this case robot will be able to access Google services on behalf of his account. Any time when access token is invalid administrator will get such email and let robot to continue his work. E.g.:
@Inject
SomeAuthorizationRequiredEmail authorizationRequiredEmail;
...
googleSheets.onAuthorization(url->{
authorizationRequiredEmail.setConsentPage(url).send();
});
...
authorizationPerformer - lambda expression or instance of AuthorizationPerformer that defines
specific behavior of authorization step.public GoogleSheets secret(String vaultAlias)
For information regarding how to configure OAuth 2.0 Client see OAuth client ID credentials
vaultAlias - the alias of secret vault entry with OAuth 2.0 Client JSON to use.public GoogleSheets secret(String userId, String secret)
The OAuth 2.0 Client JSON look like the following:
{
"installed": {
"client_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
"project_id": "XXXXXXX-XXXXXX",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_secret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"redirect_uris": [
"urn:ietf:wg:oauth:2.0:oob",
"http://localhost"
]
}
}
For information regarding how to configure OAuth 2.0 Client see
OAuth client ID credentialsuserId - user unique identifier that will be associated with secret information. This is is used as key
to store access token in StoredCredentials file.secret - JSON string with secret information to use.public SpreadsheetDocument getSpreadsheet(String spreadsheetId)
spreadsheetId - the Google file ID of necessary Google spreadsheet to get.SpreadsheetDocument representing the Google spreadsheet.Copyright © 2022. All rights reserved.