well, if anyone else needs this, here's what i did:
I have three files, the view, the start controller, and the end controller.
on the view, i have a link like this:
<g:link action="registerOnLinkedIn" controller="linkedinProfile" >connect </g:link>
where I have this method:
String apiKey =:myKey"
String apiSecret="mySecret"
String callBackUrl="http://localhost:8080/myApp/secure/mySub/success"
def registerOnLinkedIn = {
Token linkedInAccessToken=null;
OAuthService service=new ServiceBuilder()
.provider(LinkedInApi.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.callback(callBackUrl)
.build();
Token requestToken = service.getRequestToken();
String authUrl = service.getAuthorizationUrl(requestToken);
session['REQUEST_TOKEN'] = requestToken
redirect(url: authUrl)
}
def success ={
String v = params.oauth_verifier
String r= session['REQUEST_TOKEN']
linkedInXmlService.getXmlStream(v,session['REQUEST_TOKEN'])
}
When the user clicks on the link, they are sent to that method, which creates a redirect url. The redirect url is linkedIn's authorization page, where the user can accept the app. once accepted, they are redirected to the success method, which redirects to a service.
The service gets the verifier and token and sends a request to the linkedin API. the bulk of it is here:
def apiUrl = "http://api.linkedin.com/v1/people/~:(" +
"id," +
"picture-url," +
"site-standard-profile-request," +
"first-name," +
"date-of-birth," +
"last-name," +
"industry," +
"location," +
"educations," +
"positions:(id,title,summary,start-date,end-date,is-current,company)," +
"skills:(id,skill:(name),proficiency:(level),years:(name))," +
"connections:(id,industry,first-name,last-name,site-standard-profile-request,headline,location,positions,educations,date-of-birth,picture-url,skills:(id,skill:(name),proficiency:(level),years:(name)))" +
")"
public void getXmlStream(String ver, rt)
{
String accessTokenKey=""
String accessTokenSecret=""
String xmlString =""
OAuthService service=new ServiceBuilder()
.provider(LinkedInApi.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.build();
Verifier v = new Verifier(ver);
Token accessToken = service.getAccessToken(rt, v);
accessTokenSecret = accessToken.secret
accessTokenKey = accessToken.token
OAuthRequest request = new OAuthRequest(Verb.GET, apiUrl);
service.signRequest(accessToken, request); // the access token from step 4
Response response = request.send();
xmlString=response.getBody();
log.debug (xmlString)
processData(xmlString, accessTokenKey, accessTokenSecret)
}