Description
Gets the access token returned by the authorization server.
Applies to
Syntax
objectname.GetAccessToken ( )
|
Argument |
Description |
|---|---|
|
objectname |
A reference to the TokenResponse object in which you want to get the access token. |
Return value
String.
Returns the access token if it succeeds and empty string ("") if an error occurs.
Examples
The following example code can obtain the AccessToken of an Office 365 email account. This AccessToken can be used by the SMTPClient object to send emails using the XOAUTH2 type.
Long ll_rc
String ls_token, ls_type, ls_description, ls_uri, ls_state, ls_body
OAuthClient lnv_OAuthClient
TokenRequest lnv_TokenRequest
TokenResponse lnv_TokenResponse
lnv_OAuthClient = Create OAuthClient
lnv_TokenRequest.TokenLocation = "http://login.microsoftonline.com/8bb73260-fca9-43ec-8c48-1e3ce7******/oauth2/v2.0/token"
lnv_TokenRequest.Method = "POST"
lnv_TokenRequest.Clientid = "291335a5-eb93-4ed5-b2e8-770b0bb******"
lnv_TokenRequest.ClientSecret = "RTb8Q~~GR2NGTfTjpDqczxPCqP_pDpYPnw.******"
lnv_TokenRequest.Scope = "https://outlook.office365.com/.default"
lnv_TokenRequest.GrantType = "client_credentials"
lnv_TokenRequest.SecureProtocol = 0
ll_rc = lnv_OAuthClient.AccessToken(lnv_TokenRequest, lnv_TokenResponse)
If ll_rc = 1 and lnv_TokenResponse.GetStatusCode() = 200 Then
ls_token = lnv_TokenResponse.GetAccessToken()
Messagebox('AccessToken',ls_token)
else
lnv_TokenResponse.getBody(ls_body)
lnv_TokenResponse.getTokenerror(ls_type, ls_description, ls_uri, ls_state)
Messagebox('Error', "lnv_OAuthClient.AccessToken(request, lnv_TokenResponse)=" + String ( ll_rc ) + "~r~nlnv_TokenResponse.getStatuscode()=" + String ( lnv_TokenResponse.getStatuscode()) + "~r~nlnv_TokenResponse.getStatustext()=" + lnv_TokenResponse.getStatustext() +"~r~nlnv_TokenResponse.getBody(ls_body),ls_body="+ls_body )
end if
Destroy lnv_OAuthClient
See also


