无法从salesforce服务器

时间:2017-01-25 17:23:26

标签: salesforce

我无法从salesforce实例获取访问令牌,任何人都可以帮助我解决这个问题。 我尝试了许多不同的方法,但实际上无法完成它:(。

HttpClient httpclient2 = new DefaultHttpClient();
HttpPost post = new HttpPost("https://instance.salesforce.com/services/oauth2/token");
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("client_id", CONSUMER_KEY));
params.add(new BasicNameValuePair("client_secret", SECRET_KEY));
params.add(new BasicNameValuePair("grant_type", "password"));
params.add(new BasicNameValuePair("username", "emailaddress"));
params.add(new BasicNameValuePair("password", password+securityToken));
post.setEntity(new UrlEncodedFormEntity(params));
HttpResponse response = httpclient2.execute(post);
String body = EntityUtils.toString(response.getEntity());
System.out.println(body);

它给出了以下错误: {“error”:“invalid_grant”,“error_description”:“身份验证失败”}

提前致谢。

2 个答案:

答案 0 :(得分:0)

我认为问题是你需要使用login.salesforce.com作为登录主机,而不是<instance>.salesforce.com但是如果这不起作用,这里有一个使用httpclient的完整示例登录然后进行查询:https://github.com/jamesward/salesforce-rest-starter

答案 1 :(得分:0)

它已超过2天但最后,我已经完成了它:)。

程序是正确的但是Salesforce方面的配置缺少了一些东西。以下是修复我的问题的缺失配置。

enter image description here

感谢。