Error message when authorising OAuth2 token : "State token is invalid or has expired"

Hi,

I reset my OAuth2 access token this morning, and then refreshed the token. Pasted authorisation url into browser but got the message “The state token is invalid or has expired. Please try again.”

I’ve not changed anything, this has worked fine on numerous occassions.

Any suggestions.

Thanks

Code I am using is below;

function getOAuth2Access() {
var service = getService();
if (service.hasAccess()) {
// … do whatever …
} else {
var authorizationUrl = service.getAuthorizationUrl();
Logger.log(‘Open the following URL and re-run the script: %s’,
authorizationUrl);
}
}

/**
* Configures the service.
*/
function getService() {
return OAuth2.createService(‘hubspot’)
// Set the endpoint URLs.
.setTokenUrl(TOKEN_URL)
.setAuthorizationBaseUrl(AUTH_URL)

// Set the client ID and secret.
.setClientId(CLIENT_ID)
.setClientSecret(CLIENT_SECRET)

// Set the name of the callback function in the script referenced
// above that should be invoked to complete the OAuth flow.
.setCallbackFunction(‘authCallback’)

// Set the property store where authorized tokens should be persisted.
.setPropertyStore(PropertiesService.getUserProperties())
.setScope(SCOPE);
}

Resolved, I have multiple google accounts,. I think the problem was running the script in one google account and authorising in a different account.

Resolved by authorising in the same google account as the script was run, and logging in the relevant hubspot account.