GlideOAuthClient requestTokenByRequest failed to find the oauth entity

ude_zonan
Kilo Contributor

Hi

I'm trying create schedule job that generate CSV and upload it to Google drive via Google REST API but I'm having problem getting access and refresh token from the script

below are my Oauth Provider settings

find_real_file.png

find_real_file.png

I use the code below for tokens generation but the script return null on all token and   'Error:failed to find the oauth entity' error message

/******************************************************************************/

var tokenRequest = new   sn_auth.GlideOAuthClientRequest();

var oAuthClient = new   sn_auth.GlideOAuthClient();

var tokenResponse = oAuthClient.requestTokenByRequest('Google Drive default_profile',tokenRequest);

gs.log("Error:" + tokenResponse.getErrorMessage());

var token = tokenResponse.getToken();

gs.log("AccessToken:" + token.getAccessToken());

gs.log("AccessTokenExpiresIn:" + token.getExpiresIn());

gs.log(" RefreshToken:" + token.getRefreshToken());

/******************************************************************************/

Most of the example I found are using the password flow.

I have already Authorize the API via 'Get OAuth Token' link from REST Message module

I based the code on this example How to setup OAuth2 authentication for RESTMessageV2 integrations

p/s I'm new actually new to Oauth so I may have the entire concept wrong.

Thanks

1 REPLY 1

john9988
Kilo Explorer

"I have already Authorize the API via 'Get OAuth Token' link from REST Message module"


if you ready did that, the token is issued to you and you shall use REST API to get data from Google. check


RESTResponseV2 API - ServiceNow Wiki



You don't need to use " sn_auth.GlideOAuthClient" to get oauth access token again.