• Storm17
  • NEWBIE
  • 25 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Hello

 

I'm working on an app in java (Android) and I'm trying to use a refresh token to obtain a new OAuth access token.  I got the access token through the SalesForce Android toolkit, and this logs me in fine for the session, but when I use the refresh token to try to get a new access token, I get the following error:

 

{"error":"invalid_grant","error_description":"expired access/refresh token"}

 

My consumer key and secret both seem to be fine, because I get the appropriate errors when I alter them.  Has anyone else been getting this error?  Is it something to do with the URL encoding?

 

Here is the code I'm using:

 

      HttpPost httppost = new HttpPost(
          "https://login.salesforce.com/services/oauth2/token");

      List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
      nameValuePairs.add(new BasicNameValuePair("grant_type", "refresh_token"));
      nameValuePairs
          .add(new BasicNameValuePair("client_id", OAUTH_CONSUMER_KEY));
      nameValuePairs.add(new BasicNameValuePair("client_secret",
          OAUTH_CONSUMER_SECRET));
      nameValuePairs
          .add(new BasicNameValuePair("refresh_token", REFRESH_TOKEN));
      nameValuePairs.add(new BasicNameValuePair("format", "json"));

      httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

      HttpClient client = new DefaultHttpClient();
      HttpResponse response = client.execute(httppost);
      HttpEntity entity = response.getEntity();

      String responseText = EntityUtils.toString(entity);

Hello

 

I'm working on an app in java (Android) and I'm trying to use a refresh token to obtain a new OAuth access token.  I got the access token through the SalesForce Android toolkit, and this logs me in fine for the session, but when I use the refresh token to try to get a new access token, I get the following error:

 

{"error":"invalid_grant","error_description":"expired access/refresh token"}

 

My consumer key and secret both seem to be fine, because I get the appropriate errors when I alter them.  Has anyone else been getting this error?  Is it something to do with the URL encoding?

 

Here is the code I'm using:

 

      HttpPost httppost = new HttpPost(
          "https://login.salesforce.com/services/oauth2/token");

      List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
      nameValuePairs.add(new BasicNameValuePair("grant_type", "refresh_token"));
      nameValuePairs
          .add(new BasicNameValuePair("client_id", OAUTH_CONSUMER_KEY));
      nameValuePairs.add(new BasicNameValuePair("client_secret",
          OAUTH_CONSUMER_SECRET));
      nameValuePairs
          .add(new BasicNameValuePair("refresh_token", REFRESH_TOKEN));
      nameValuePairs.add(new BasicNameValuePair("format", "json"));

      httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

      HttpClient client = new DefaultHttpClient();
      HttpResponse response = client.execute(httppost);
      HttpEntity entity = response.getEntity();

      String responseText = EntityUtils.toString(entity);