Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Java Development
- :
- "expired access/refresh token" while trying to au...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
"expired access/ref resh token" while trying to authentifi cate
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
10-11-2012 02:41 AM
We try to download a file provided by salesforce with simple java client. For that request authentication is required. But the URL call always returns "expired access/refresh token".
The source code:
public static void connect()
{
HttpClient httpclient = new DefaultHttpClient();
HttpParams httpParams = httpclient.getParams();
HttpClientParams.setCookiePolicy(httpParams, CookiePolicy.RFC_2109);
httpParams.setParameter(HttpConnectionParams.CONNE
HttpPost postMethod = new HttpPost("https://login.salesforce.com/services/oauth2/token");
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("client_id", MY_CLIENT_ID));
params.add(new BasicNameValuePair("client_secret", MY_SECRET));
params.add(new BasicNameValuePair("grant_type", "password"));
params.add(new BasicNameValuePair("username", MY_USERNAME));
params.add(new BasicNameValuePair("password", MY_PASSWORD + SECURITY_TOKEN));
try
{
postMethod.setEntity(new UrlEncodedFormEntity(params, Consts.UTF_8));
HttpResponse response = httpclient.execute(postMethod);
InputStream content = response.getEntity().getContent();
JSONObject authResponse = new JSONObject(new JSONTokener(new InputStreamReader(content)));
System.out.println("Auth response: " + authResponse.toString(2));
String accessToken = authResponse.getString("access_token"); // throws exception JSONObject["access_token"] not found.
System.out.println("Got access token: " + accessToken);
}
catch (Exception e)
{
e.printStackTrace();
}
}
The output ot the code snippet:
Auth response: {
"error": "invalid_grant",
"error_description": "expired access/refresh token"
}
Kind regards.

