Class Info |
|---|
public class DriveCredential implements HttpExecuteInterceptor, HttpRequestInitializer, HttpUnsuccessfulResponseHandler Drive authentication class. HttpExecuteInterceptor: HTTP request execution interceptor. HttpRequestInitializer: HTTP request initializer. HttpUnsuccessfulResponseHandler: API for handling abnormal HTTP responses. |
Qualifier and Type | Class Name and Description |
|---|---|
class | Declaration of the DriveCredential.Builder class. |
@interface | Object used to obtain a new access token when the original one expires. Its abstract method refreshToken() needs to be implemented in a subclass. |
Constructor Name |
|---|
DriveCredential(String unionID, AccessMethod method) Constructs a DriveCredential object. |
Qualifier and Type | Method Name and Description |
|---|---|
clone() Clones a DriveCredential object. | |
final String | Obtains an access token. |
final Long | getExpirationTimeMilliseconds() Obtains the validity period of an access token. |
String | Obtains the UnionID of the user. |
boolean | handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry) Re-obtains authentication information and sends a new request if a request fails due to an authentication failure. |
void | initialize(HttpRequest request) Initializes a request. |
void | intercept(HttpRequest request) Intercepts a request to configure request authentication information. |
boolean | Obtains a new access token. |
setAccessToken(String accessToken) Sets an access token. | |
setExpiresInSeconds(Long expiresIn) Sets the validity period of an access token. |
Constructor |
|---|
public DriveCredential(String unionID, AccessMethod method) Constructs a DriveCredential object. |
Parameters
Name | Description |
|---|---|
unionID | UnionID obtained after a user signs in using a HUAWEI ID. |
method | DriveCredential.AccessMethod object, which is used to obtain a new access token when the original one expires. |
Method |
|---|
public void intercept(HttpRequest request) throws IOException Intercepts a request to configure request authentication information. |
Parameters
Name | Description |
|---|---|
request | HTTP request. |
Throws
Name | Description |
|---|---|
java.io.IOException | I/O exception thrown upon an API call failure. You can use the getMessage method to obtain the error description. |
Method |
|---|
public boolean handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry) Re-obtains authentication information and sends a new request if a request fails due to an authentication failure. |
Parameters
Name | Description |
|---|---|
request | HTTP request. |
response | Response to be processed. |
supportsRetry | Indicates whether an API can be called again upon a call failure. |
Returns
Type | Description |
|---|---|
boolean | true if an API call is successful; false otherwise. |
Method |
|---|
public void initialize(HttpRequest request) Initializes a request. |
Parameters
Name | Description |
|---|---|
request | HTTP request. |
Method |
|---|
public String getUnionID() Obtains the UnionID of the user. |
Returns
Type | Description |
|---|---|
String | UnionID obtained after a user signs in using a HUAWEI ID. |
Method |
|---|
public final String getAccessToken() Obtains an access token. |
Returns
Type | Description |
|---|---|
final String | Access token. |
Method |
|---|
public DriveCredential setAccessToken(String accessToken) Sets an access token. |
Parameters
Name | Description |
|---|---|
accessToken | Authentication information. |
Returns
Type | Description |
|---|---|
DriveCredential | A DriveCredential object. |
Method |
|---|
public DriveCredential setExpiresInSeconds(Long expiresIn) Sets the validity period of an access token. |
Parameters
Name | Description |
|---|---|
expiresIn | Validity period of an access token, in seconds. |
Returns
Type | Description |
|---|---|
DriveCredential | A DriveCredential object. |
Method |
|---|
public final Long getExpirationTimeMilliseconds() Obtains the validity period of an access token. |
Returns
Type | Description |
|---|---|
final Long | Validity period of an access token. |
Method |
|---|
public boolean refreshToken() throws IOException Obtains a new access token. |
Returns
Type | Description |
|---|---|
boolean | true if a new access token is successfully obtained; false otherwise. |
Throws
Name | Description |
|---|---|
java.io.IOException | I/O exception thrown upon an API call failure. You can use the getMessage method to obtain the error description. |