Chilkat Online Tools

Android / Salesforce Platform APIs / User Info

Back to Collection Items

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttp http = new CkHttp();
    boolean success;

    http.SetRequestHeader("Content-Type","application/json");

    CkStringBuilder sbResponseBody = new CkStringBuilder();
    success = http.QuickGetSb("https://login.salesforce.com{{site}}/services/oauth2/userinfo",sbResponseBody);
    if (success == false) {
        Log.i(TAG, http.lastErrorText());
        return;
        }

    CkJsonObject jResp = new CkJsonObject();
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    Log.i(TAG, "Response Body:");
    Log.i(TAG, jResp.emit());

    int respStatusCode = http.get_LastStatus();
    Log.i(TAG, "Response Status Code = " + String.valueOf(respStatusCode));
    if (respStatusCode >= 400) {
        Log.i(TAG, "Response Header:");
        Log.i(TAG, http.lastHeader());
        Log.i(TAG, "Failed.");
        return;
        }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "sub": "https://login.salesforce.com/id/00D.../005...",
    //   "user_id": "005...",
    //   "organization_id": "00D...",
    //   "preferred_username": "<username>",
    //   "nickname": "<nickname>",
    //   "name": "<name>",
    //   "email": "<email>",
    //   "email_verified": true,
    //   "given_name": "<name>",
    //   "family_name": "<name>",
    //   "zoneinfo": "Europe/Paris",
    //   "photos": {
    //     "picture": "https://<file_domain>/profilephoto/005/F",
    //     "thumbnail": "https://<file_domain>/profilephoto/005/T"
    //   },
    //   "profile": "https://<my_domain>/005",
    //   "picture": "https://<file_domain>/profilephoto/005/F",
    //   "address": {
    //     "country": "FR"
    //   },
    //   "is_salesforce_integration_user": false,
    //   "urls": {
    //     "enterprise": "https://<my_domain>/services/Soap/c/{version}/00D...",
    //     "metadata": "https://<my_domain>/services/Soap/m/{version}/00D...",
    //     "partner": "https://<my_domain>/services/Soap/u/{version}/00D...",
    //     "rest": "https://<my_domain>/services/data/v{version}/",
    //     "sobjects": "https://<my_domain>/services/data/v{version}/sobjects/",
    //     "search": "https://<my_domain>/services/data/v{version}/search/",
    //     "query": "https://<my_domain>/services/data/v{version}/query/",
    //     "recent": "https://<my_domain>/services/data/v{version}/recent/",
    //     "tooling_soap": "https://<my_domain>/services/Soap/T/{version}/00D...",
    //     "tooling_rest": "https://<my_domain>/services/data/v{version}/tooling/",
    //     "profile": "https://<my_domain>/0052o00000DOJ1PAAX",
    //     "feeds": "https://<my_domain>/services/data/v{version}/chatter/feeds",
    //     "groups": "https://<my_domain>/services/data/v{version}/chatter/groups",
    //     "users": "https://<my_domain>/services/data/v{version}/chatter/users",
    //     "feed_items": "https://<my_domain>/services/data/v{version}/chatter/feed-items",
    //     "feed_elements": "https://<my_domain>/services/data/v{version}/chatter/feed-elements",
    //     "custom_domain": "https://<my_domain>"
    //   },
    //   "active": true,
    //   "user_type": "STANDARD",
    //   "language": "en_US",
    //   "locale": "fr_FR_EURO",
    //   "utcOffset": 3600000,
    //   "updated_at": "<datetime>",
    //   "is_app_installed": true
    // }

    // Sample code for parsing the JSON response...
    // Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    String v_sub = jResp.stringOf("sub");
    String user_id = jResp.stringOf("user_id");
    String organization_id = jResp.stringOf("organization_id");
    String preferred_username = jResp.stringOf("preferred_username");
    String nickname = jResp.stringOf("nickname");
    String name = jResp.stringOf("name");
    String email = jResp.stringOf("email");
    boolean email_verified = jResp.BoolOf("email_verified");
    String given_name = jResp.stringOf("given_name");
    String family_name = jResp.stringOf("family_name");
    String zoneinfo = jResp.stringOf("zoneinfo");
    String Picture = jResp.stringOf("photos.picture");
    String Thumbnail = jResp.stringOf("photos.thumbnail");
    String profile = jResp.stringOf("profile");
    String picture = jResp.stringOf("picture");
    String Country = jResp.stringOf("address.country");
    boolean is_salesforce_integration_user = jResp.BoolOf("is_salesforce_integration_user");
    String Enterprise = jResp.stringOf("urls.enterprise");
    String Metadata = jResp.stringOf("urls.metadata");
    String Partner = jResp.stringOf("urls.partner");
    String v_Rest = jResp.stringOf("urls.rest");
    String Sobjects = jResp.stringOf("urls.sobjects");
    String Search = jResp.stringOf("urls.search");
    String Query = jResp.stringOf("urls.query");
    String Recent = jResp.stringOf("urls.recent");
    String Tooling_soap = jResp.stringOf("urls.tooling_soap");
    String Tooling_rest = jResp.stringOf("urls.tooling_rest");
    String Profile = jResp.stringOf("urls.profile");
    String Feeds = jResp.stringOf("urls.feeds");
    String Groups = jResp.stringOf("urls.groups");
    String Users = jResp.stringOf("urls.users");
    String Feed_items = jResp.stringOf("urls.feed_items");
    String Feed_elements = jResp.stringOf("urls.feed_elements");
    String Custom_domain = jResp.stringOf("urls.custom_domain");
    boolean active = jResp.BoolOf("active");
    String user_type = jResp.stringOf("user_type");
    String language = jResp.stringOf("language");
    String locale = jResp.stringOf("locale");
    int utcOffset = jResp.IntOf("utcOffset");
    String updated_at = jResp.stringOf("updated_at");
    boolean is_app_installed = jResp.BoolOf("is_app_installed");

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

Curl Command

curl -X GET
	-H "Content-Type: application/json"
https://login.salesforce.com{{site}}/services/oauth2/userinfo

Postman Collection Item JSON

{
  "name": "User Info",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{url}}{{site}}/services/oauth2/userinfo",
      "host": [
        "{{url}}{{site}}"
      ],
      "path": [
        "services",
        "oauth2",
        "userinfo"
      ]
    }
  },
  "response": [
    {
      "name": "Successful User Info",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{url}}{{site}}/services/oauth2/userinfo",
          "host": [
            "{{url}}{{site}}"
          ],
          "path": [
            "services",
            "oauth2",
            "userinfo"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Thu, 16 Nov 2023 15:35:50 GMT"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=63072000; includeSubDomains"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "X-Robots-Tag",
          "value": "none"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache,must-revalidate,max-age=0,no-store,private"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=UTF-8"
        },
        {
          "key": "Vary",
          "value": "Accept-Encoding"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"sub\": \"https://login.salesforce.com/id/00D.../005...\",\n    \"user_id\": \"005...\",\n    \"organization_id\": \"00D...\",\n    \"preferred_username\": \"<username>\",\n    \"nickname\": \"<nickname>\",\n    \"name\": \"<name>\",\n    \"email\": \"<email>\",\n    \"email_verified\": true,\n    \"given_name\": \"<name>\",\n    \"family_name\": \"<name>\",\n    \"zoneinfo\": \"Europe/Paris\",\n    \"photos\": {\n        \"picture\": \"https://<file_domain>/profilephoto/005/F\",\n        \"thumbnail\": \"https://<file_domain>/profilephoto/005/T\"\n    },\n    \"profile\": \"https://<my_domain>/005\",\n    \"picture\": \"https://<file_domain>/profilephoto/005/F\",\n    \"address\": {\n        \"country\": \"FR\"\n    },\n    \"is_salesforce_integration_user\": false,\n    \"urls\": {\n        \"enterprise\": \"https://<my_domain>/services/Soap/c/{version}/00D...\",\n        \"metadata\": \"https://<my_domain>/services/Soap/m/{version}/00D...\",\n        \"partner\": \"https://<my_domain>/services/Soap/u/{version}/00D...\",\n        \"rest\": \"https://<my_domain>/services/data/v{version}/\",\n        \"sobjects\": \"https://<my_domain>/services/data/v{version}/sobjects/\",\n        \"search\": \"https://<my_domain>/services/data/v{version}/search/\",\n        \"query\": \"https://<my_domain>/services/data/v{version}/query/\",\n        \"recent\": \"https://<my_domain>/services/data/v{version}/recent/\",\n        \"tooling_soap\": \"https://<my_domain>/services/Soap/T/{version}/00D...\",\n        \"tooling_rest\": \"https://<my_domain>/services/data/v{version}/tooling/\",\n        \"profile\": \"https://<my_domain>/0052o00000DOJ1PAAX\",\n        \"feeds\": \"https://<my_domain>/services/data/v{version}/chatter/feeds\",\n        \"groups\": \"https://<my_domain>/services/data/v{version}/chatter/groups\",\n        \"users\": \"https://<my_domain>/services/data/v{version}/chatter/users\",\n        \"feed_items\": \"https://<my_domain>/services/data/v{version}/chatter/feed-items\",\n        \"feed_elements\": \"https://<my_domain>/services/data/v{version}/chatter/feed-elements\",\n        \"custom_domain\": \"https://<my_domain>\"\n    },\n    \"active\": true,\n    \"user_type\": \"STANDARD\",\n    \"language\": \"en_US\",\n    \"locale\": \"fr_FR_EURO\",\n    \"utcOffset\": 3600000,\n    \"updated_at\": \"<datetime>\",\n    \"is_app_installed\": true\n}"
    }
  ]
}