目录

Class info
public class DriveCredential implements HttpExecuteInterceptor, HttpRequestInitializer, HttpUnsuccessfulResponseHandler
Drive authentication class.

Nested Class Summary

TypeNameDesc
classDriveCredential.BuilderDeclaration of the DriveCredential.Builder class.
@interfaceDriveCredential.AccessMethodObject used to obtain a new access token when the original one expires.

Public Constructor Summary

Constructor name

DriveCredential(String unionID, AccessMethod method)

Constructor for the DriveCredential class.

Public Method Summary

Return typeMethod name
void

intercept(HttpRequest request)

Intercepts a request to configure request authentication information.

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.

String

getUnionID()

Obtains the unique ID of a user.

final String

getAccessToken()

Obtains an access token.

DriveCredential

setAccessToken(String accessToken)

Sets an access token.

DriveCredential

setExpiresInSeconds(Long expiresIn)

Sets the validity period of an access token.

final Long

getExpirationTimeMilliseconds()

Obtains the validity period of an access token.

boolean

refreshToken()

Obtains a new access token.

DriveCredential

clone()

Clones a DriveCredential object.

Public Constructors

constructor
public DriveCredential(String unionID, AccessMethod method)
Constructs a DriveCredential object.

Parameters

Parameter nameParameter desc
unionIDUnion ID, which is a unique user ID obtained after a user signs in using a HUAWEI ID.
methodDriveCredential.AccessMethod object, which is used to obtain a new access token when the original one expires.

Public Methods

Method
public void intercept(HttpRequest request) throws IOException
Intercepts a request to configure request authentication information.

Parameters

Parameter nameParameter desc
requestHTTP request.

Throws

Parameter nameParameter desc
java.io.IOExceptionI/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

Parameter nameParameter desc
requestHTTP request.
responseResponse to be processed.
supportsRetryIndicates whether an API can be called again upon a call failure.

Return

typedesc
booleanWhether an API call is successful. If the API call is successful, true is returned. Otherwise, false is returned.
Method


public void initialize(HttpRequest request)

Initializes a request.

Parameters

Parameter nameParameter desc
requestHTTP request.
Method


Method

public String getUnionID()

Obtains the unique ID of a user.

Return

typedesc
StringUnion ID, which is a unique user ID obtained after a user signs in using a HUAWEI ID.
Method


public final String getAccessToken()

Obtains an access token.

Return

typedesc
final StringAuthentication information containing the access token.
Method


public DriveCredential setAccessToken(String accessToken)

Sets an access token.

Parameters

Parameter nameParameter desc
accessTokenAuthentication information containing the access token.

Return

typedesc
DriveCredentialAn DriveCredential object.
Method


public DriveCredential setExpiresInSeconds(Long expiresIn)

Sets the validity period of an access token.

Parameters

Parameter nameParameter desc
expiresInValidity period of an access token, in milliseconds.

Return

typedesc
DriveCredentialAn DriveCredential object.
Method


public final Long getExpirationTimeMilliseconds()

Obtains the validity period of an access token.

Return

typedesc
final LongValidity period of an access token.
Method


public boolean refreshToken() throws IOException

Obtains a new access token.

Return

typedesc
boolean

true: A new access token is successfully obtained.

false: A new access token fails to be obtained.

Method


public DriveCredential clone()

Clones a DriveCredential object.

Return

typedesc
DriveCredentialA DriveCredential object.