Hi Humashankar
I tried the following but it gives me an error message. Something is missing in my code.
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1');
import groovyx.net.http.RESTClient;
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method
import groovyx.net.http.ContentType
def clientId = "5LM";
def redirectUri = "https://readyapi/callback";
def authorizationUrl = "https://abc.com/authorize";
def authUrl = "${authorizationUrl}?client_id=${clientId}&redirect_uri=${redirectUri}&response_type=token";
//def clientSecret = ?;
def http = new HTTPBuilder(tokenUrl)
http.request(Method.POST, ContentType.URLENC) { req ->
body = [
grant_type: 'client_credentials',
client_id: clientId
]
response.success = { resp, reader ->
// Extract the access token from the response
def accessToken = resp.data.access_token
// Now we can use the access token to make API requests
println accessToken
//println "Please visit the following URL to grant access:\n${authUrl}";
This is the error I get:
The following script is invalid: @Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1'); import groovyx.net.http.RESTClient; import groovyx.net.http.HTTPBuilder import groovyx.net.http.Method import groovyx.net.http.ContentType def clientId = "5LM"; def redirectUri = "https://readyapi/callback"; def authorizationUrl = "https://abc.com/authorize"; def authUrl = "${authorizationUrl}?client_id=${clientId}&redirect_uri=${redirectUri}&response_type=token"; //def clientSecret = ?; def http = new HTTPBuilder(tokenUrl) http.request(Method.POST, ContentType.URLENC) { req -> body = [ grant_type: 'client_credentials', client_id: clientId ] response.success = { resp, reader -> // Extract the access token from the response def accessToken = resp.data.access_token // Now we can use the access token to make API requests println accessToken //println "Please visit the following URL to grant access:\n${authUrl}";
Error: missing ; before statement (scriptToValidate#2)