You need to sign in to do that
Don't have an account?
could not get access token with error "invalid authorization code"
Hi, all
Followed with "http://www.salesforce.com/us/developer/docs/api_rest/Content/quickstart_oauth.htm", I'm trying to make a simple client test code to pass. Unfortunately, I could get the authorization token, but when could not get access token, and the response I got when requiring access token is :
{"error":"invalid_grant","error_description":"invalid authorization code"}.
Following is my test code
step1: Registry one remote app, and get customer_key and customer_secret
customer key: 3MVG9Y6d_Btp4xp4S0UExFwosGGJCLQZq3k8mUbBu6DoVNiWVlxqKMHCzpPi4DHx9b.PsxqacuY5hwpGFlxCM
customer secret: 7497167051685992293
step2: Open browser, access following url, which includes the required parameters, as below
Step3: Get authorization token from the browser address bar
Step4: Try to get access token with following code:
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("https://login.salesforce.com/services/oauth2/token");
post.setParameter("grant_type","authorization_code");
post.setParameter("client_id","3MVG9Y6d_Btp4xp4S0UExFwosGGJCLQZq3k8mUbBu6DoVNiWVlxqKMHCzpPi4DHx9b.PsxqacuY5hwpGFlxCM");
post.setParameter("client_secret","7497167051685992293");
post.setParameter("redirect_uri","https://10.111.3.82:8443");
post.setParameter("code", "aPrxaSyVmC8fBbeBsvplbPnf.sN3TAsh8c2Dnrrxbd203sy7T1m8WbTWtknf_EqNJEZDh3DYIQ%3D%3D");
post.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
client.executeMethod(post);
String responseBody = post.getResponseBodyAsString();
String accessToken = null;
JSONObject json = null;
try {
json = new JSONObject(responseBody);
accessToken = json.getString("access_token");
} catch (JSONException e) {
e.printStackTrace();
}
Unfortunately, I always get responseBody as below
{"error":"invalid_grant","error_description":"invalid authorization code"}
Please help!