Class SheetsServiceProvider
The Sheets service provider performs the authentication to Google and keeps track of the authentication tokens so that you do not need to authenticate each time. The Sheets service provider also includes general sheet properties, such as default sheet styles, that are used when creating a new sheet.
Inherited Members
Namespace: UnityEditor.Localization.Plugins.Google
Syntax
[CreateAssetMenu(fileName = "Google Sheets Service", menuName = "Localization/Google Sheets Service")]
[HelpURL("https://developers.google.com/sheets/api/guides/authorizing#AboutAuthorization")]
public class SheetsServiceProvider : ScriptableObject, IGoogleSheetsService, ISerializationCallbackReceiver
Examples
Unity recommends to have a SheetsServiceProvider asset pre-configured for use, however this example does create a new one.
// The Sheets service provider performs the authentication and keeps track of the
// authentication tokens so that we do not need to authenticate each time.
// It is recommended to have a SheetsServiceProvider asset pre-configured for
// use however in this example we will create a new one.
var sheetServiceProvider = ScriptableObject.CreateInstance<SheetsServiceProvider>();
// OAuth is required when making changes. See the docs for info setting up OAuth credentials.
sheetServiceProvider.SetOAuthCredentials("some-client-id", "some-client-secret");
return sheetServiceProvider;
Properties
ApiKey
The API Key to use when using APIKey authentication.
Declaration
public string ApiKey { get; }
Property Value
Type | Description |
---|---|
String |
ApplicationName
The name of the application that will be sent when connecting.
Declaration
public string ApplicationName { get; set; }
Property Value
Type | Description |
---|---|
String |
Authentication
The authorization methodology to use. See https://developers.google.com/sheets/api/guides/authorizing
Declaration
public AuthenticationType Authentication { get; }
Property Value
Type | Description |
---|---|
AuthenticationType |
ClientId
Client Id when using OAuth authentication.
See also SetOAuthCredentials(String)Declaration
public string ClientId { get; }
Property Value
Type | Description |
---|---|
String |
ClientSecret
Client secret when using OAuth authentication.
See also SetOAuthCredentials(String)Declaration
public string ClientSecret { get; }
Property Value
Type | Description |
---|---|
String |
DataStore
Used to make sure the access and refresh tokens persist. Uses a FileDataStore by default with "Library/Google/{name}" as the path.
Declaration
public IDataStore DataStore { get; set; }
Property Value
Type | Description |
---|---|
IDataStore |
NewSheetProperties
Properties to use when creating a new Google Spreadsheet sheet.
Declaration
public NewSheetProperties NewSheetProperties { get; set; }
Property Value
Type | Description |
---|---|
NewSheetProperties |
Service
The Google Sheet service that will be created using the Authorization API.
Declaration
public virtual SheetsService Service { get; }
Property Value
Type | Description |
---|---|
SheetsService |
Implements
Methods
AuthoizeOAuth()
Call to preauthorize when using OAuth authorization. This will cause a browser to open a Google authorization page after which the token will be stored in IDataStore so that this does not need to be done each time. If this is not called then the first time Service is called it will be performed then.
Declaration
[Obsolete("AuthoizeOAuth is deprecated, use AuthorizeOAuth instead. (UnityUpgrade) -> AuthorizeOAuth(*)")]
public void AuthoizeOAuth()
AuthorizeOAuth()
Call to preauthorize when using OAuth authorization. This will cause a browser to open a Google authorization page after which the token will be stored in IDataStore so that this does not need to be done each time. If this is not called then the first time Service is called it will be performed then.
Declaration
public UserCredential AuthorizeOAuth()
Returns
Type | Description |
---|---|
UserCredential |
AuthorizeOAuthAsync(CancellationToken)
Call to preauthorize when using OAuth authorization. This will cause a browser to open a Google authorization page after which the token will be stored in IDataStore so that this does not need to be done each time. If this is not called then the first time Service is called it will be performed then.
Declaration
public Task<UserCredential> AuthorizeOAuthAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | Token that can be used to cancel the task prematurely. |
Returns
Type | Description |
---|---|
Task<UserCredential> | The authorization Task that can be monitored. |
SetApiKey(String)
Set the API Key. An API key can only be used for reading from a public Google Spreadsheet.
Declaration
public void SetApiKey(string apiKey)
Parameters
Type | Name | Description |
---|---|---|
String | apiKey |
SetOAuthCredentials(String)
Enable OAuth 2.0 authentication and extract the ClientId and ClientSecret from the supplied json.
Declaration
public void SetOAuthCredentials(string credentialsJson)
Parameters
Type | Name | Description |
---|---|---|
String | credentialsJson |
SetOAuthCredentials(String, String)
Enable OAuth 2.0 authentication with the provided client Id and client secret.
Declaration
public void SetOAuthCredentials(string clientId, string clientSecret)
Parameters
Type | Name | Description |
---|---|---|
String | clientId | |
String | clientSecret |
SetOAuthCrendtials(String)
Enable OAuth 2.0 authentication and extract the ClientId and ClientSecret from the supplied json.
Declaration
[Obsolete("SetOAuthCrendtials is deprecated, use SetOAuthCredentials instead. (UnityUpgrade) -> SetOAuthCredentials(*)")]
public void SetOAuthCrendtials(string credentialsJson)
Parameters
Type | Name | Description |
---|---|---|
String | credentialsJson |
SetOAuthCrendtials(String, String)
Enable OAuth 2.0 authentication and extract the ClientId and ClientSecret from the supplied json.
Declaration
[Obsolete("SetOAuthCrendtials is deprecated, use SetOAuthCredentials instead. (UnityUpgrade) -> SetOAuthCredentials(*)")]
public void SetOAuthCrendtials(string clientId, string clientSecret)
Parameters
Type | Name | Description |
---|---|---|
String | clientId | |
String | clientSecret |