function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
drewid22drewid22 

Unable to obtain OAuth keys via Chatter REST API in Java by any means

Hello,

 

I am new to all the force.com stuff, so please forgive me if I am using the wrong terminology or am unclear. I will try to be as clear as I can. 

 

My goal is to build a java application that periodically monitors a user chatter stream. I am not running this code via a web browser or application server - this is pure java on the command line. I have setup a test remote application and have a valid client key and client secret key.

 

My goal is to have the user enter a username/password for the initial authentication and then to use the access_token / refresh_token flow for subsequent runs. Thus, in the User-Agent flow code below, my callback URI doesn't really point to anything legitimate - I want to do this all in code if possible.

 

Trying to implement the User-Agent flow as described here (http://www.salesforce.com/us/developer/docs/chatterapi/index.htm , "Understanding the User-Agent OAuth Flow" article), my code looks like this:

 

----

// chatter.auth.url == https://login.salesforce.com/services/oauth2/authorize

String hostUrl = System.getProperty("chatter.auth.url"); 


String clientId = System.getProperty("chatter.oauth.consumerKey");
String clientSecret = System.getProperty("chatter.oauth.consumerSecret");


HttpPost post = new HttpPost(hostUrl);

HttpParams params = new BasicHttpParams();
params.setParameter("client_id", clientId);

params.setParameter("redirect_uri", "https%3A%2F%2Flocalhost%3A8080%2FConnectTest%2Foauth%2F_callback");
params.setParameter("response_type", "token");
post.setParams(params);

 

response = clientService.execute(post);

 

----

 

When I run the above code, I receive a response that says "error=unsupported_response_type&error_description=response%20type%20not%20supported"

 

I have tried another API reference which uses the password method of OAuth authentication (http://www.salesforce.com/us/developer/docs/chatterapi/index.htm , "Step Two: Connect to Chatter API Using OAuth"). Based on that article, my code looks like this:

 

----

// chatter.token.url == https://na14.salesforce.com/services/oauth2/token

String hostUrl = System.getProperty("chatter.token.url");  
String clientId = System.getProperty("chatter.oauth.consumerKey");
String clientSecret = System.getProperty("chatter.oauth.consumerSecret");


HttpPost post = new HttpPost(hostUrl);
post.setHeader("Content-Type", "application/x-www-form-urlencoded");

HttpParams params = new BasicHttpParams();
params.setParameter("grant_type", "password");
params.setParameter("client_id", clientId);
params.setParameter("client_secret", clientSecret);
params.setParameter("username", username);
params.setParameter("password", password);
post.setParams(params);

 

response = clientService.execute(post);

 

----

 

When I execute the above code, I get a JSON response that says "error:  grant_type_unsupported". The short of it is that I cannot get an authorization token or a session token or anything else returned from my attempts to connect via OAuth. 

 

What am I doing wrong here or missing?  I am very confused and can't get any code that I have found in the API documentation to work and provide the documented response. 

 

Any help at all would be greatly appreciated!

Mouse.liuMouse.liu

First should be get request, second should be wrong login uri, correct one should be 

https://login.salesforce.com/services/oauth2/token