目录

DriveCredential

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.

Nested Class Summary

Qualifier and Type

Class Name and Description

class

DriveCredential.Builder

Declaration of the DriveCredential.Builder class.

@interface

DriveCredential.AccessMethod

Object used to obtain a new access token when the original one expires.

Its abstract method refreshToken() needs to be implemented in a subclass.

Public Constructor Summary

Constructor Name

DriveCredential(String unionID, AccessMethod method)

Constructs a DriveCredential object.

Public Method Summary

Qualifier and Type

Method Name and Description

DriveCredential

clone()

Clones a DriveCredential object.

final String

getAccessToken()

Obtains an access token.

final Long

getExpirationTimeMilliseconds()

Obtains the validity period of an access token.

String

getUnionID()

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

refreshToken()

Obtains a new access token.

DriveCredential

setAccessToken(String accessToken)

Sets an access token.

DriveCredential

setExpiresInSeconds(Long expiresIn)

Sets the validity period of an access token.

Public Constructors

[h2]DriveCredential

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.

Public Methods

[h2]intercept

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.

[h2]handleResponse

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.

[h2]initialize

Method

public void initialize(HttpRequest request)

Initializes a request.

Parameters

Name

Description

request

HTTP request.

[h2]getUnionID

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.

[h2]getAccessToken

Method

public final String getAccessToken()

Obtains an access token.

Returns

Type

Description

final String

Access token.

[h2]setAccessToken

Method

public DriveCredential setAccessToken(String accessToken)

Sets an access token.

Parameters

Name

Description

accessToken

Authentication information.

Returns

Type

Description

DriveCredential

A DriveCredential object.

[h2]setExpiresInSeconds

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.

[h2]getExpirationTimeMilliseconds

Method

public final Long getExpirationTimeMilliseconds()

Obtains the validity period of an access token.

Returns

Type

Description

final Long

Validity period of an access token.

[h2]refreshToken

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.

[h2]clone

Method

public DriveCredential clone()

Clones a DriveCredential object.

Returns

Type

Description

DriveCredential

A DriveCredential object.