0

First of all please look at my code below:

    List<BasicNameValuePair> qsList = new ArrayList<BasicNameValuePair>();
    qsList.add(new BasicNameValuePair("oauth_token", accessToken));
    String queryString = URLEncodedUtils.format(qsList, HTTP.UTF_8);
    HttpGet userInfoRequest = new HttpGet(id + "?" + queryString);
    DefaultHttpClient defaultHttpClientclient = new DefaultHttpClient();

    HttpResponse userInfoResponse;
    try {
        userInfoResponse = defaultHttpClientclient.execute(userInfoRequest);
        String responseBody = EntityUtils.toString(userInfoResponse.getEntity());
        System.out.println("User info response: " + responseBody);
        System.out.println("");
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

I got an access token from Salesforce. Now I request user's information via that token. In the responseBody I got all infomation of that user like username, id, language,... Now I need to take only username from the response. What should I do to take it?

gamo
  • 1,549
  • 7
  • 24
  • 36

1 Answers1

1

The response is likely in JSON. If so you can parse the data you need. I won't repost the code, instead please see: How to parse JSON in Java

    JSONObject responseJSON = new JSONObject(EntityUtils.toString(userInfoResponse.getEntity());
    String username = responseJSON.getString("username");
Community
  • 1
  • 1
ryandlf
  • 27,155
  • 37
  • 106
  • 162