HttpClient httpClient = new HttpClient();
    PostMethod post = new PostMethod(environment);
    post.addParameter("code", code);
    post.addParameter("grant_type", "authorization_code");
    post.addParameter("redirect_uri", "https://******.ngrok.io/auth");
    post.addParameter("client_id", "3MVG9d8..z.hDcPLDlm9QqJ3hRa..IRUJdGRp4Shjuu01GT.H5KRjos_xlbZEtYGy55M6SzOOELg7sfD4T6Pl");
    post.addParameter("client_secret", "*********");

After executing this I get an access token:

accessToken = jsonObject.get("access_token").getAsString(); useridURL = jsonObject.get("id").getAsString();

with which I try to fire a get method to get the userinfo:

    GetMethod getMethod = new GetMethod(useridURL);
    getMethod.addRequestHeader("oauth_token", accessToken);
    String responseUserName = getMethod.getResponseBodyAsString();

but I always get this error: Missing_OAuth_Token, I am not sure if I am missing something here?


The header you are setting in GET request is not proper.

it should be Authorization instead of oauth_token.

According to SF docs:

To call the doGet method from a client, open a command-line window and execute the following cURL command to retrieve an account by ID:

curl -H "Authorization: Bearer sessionId" "https://instance.salesforce.com/yourURL"

Thus your code will be:

getMethod.addRequestHeader("Authorization", "Bearer "+accessToken);

SRC: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest_code_sample_basic.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.