}
public AccessToken build(String code) throws Exception {
if (getClientSecret() == null || getClientId() == null
|| getRedirectUri() == null) {
throw new InstagramException("Please make sure that the"
+ "clientId, clientSecret and redirectUri fields are set");
}
HashMap<String, Object> postArgs = new HashMap<String, Object>();
postArgs.put("client_id", getClientId());
postArgs.put("client_secret", getClientSecret());
postArgs.put("grant_type", "authorization_code");
postArgs.put("redirect_uri", getRedirectUri());
if(getScope() != null && getScope() != "" ) {
postArgs.put("scope", getScope());
}
postArgs.put("code", code);
JSONObject response = (new PostMethod() .setPostParameters(postArgs)
.setMethodURI(UriFactory.Auth.GET_ACCESS_TOKEN) ).call().getJSON();
try {
setAccessToken(new
AccessToken(response.getString("access_token")));
setSessionUser(new User(response.getJSONObject("user"),
getAccessToken().getTokenString()));
} catch (Exception e) {
throw new InstagramException("JSON parsing error");
}
return getAccessToken();
}