I am using Enterprise WSDL for salesforce integration. Currently I am able to authenticate user with salesforce account and able to get the Refresh_Token & Access_Token successfully. Can any one please tell me how can I pass the Access_Token in request when I am using Web Service. Because in salesforce documentation they have specified only direct Login process but not the OAuth process.
-
you need to just access salesforce with soap or use aouth for an app third party app?– highfiveCommented Mar 6, 2014 at 9:36
-
Thanks for your reply. Like currently i am using direct login process with the below code string username = "************@gmail.com"; string password = "xz6isl77KwS4sO5Qhj"; int retryCount = 0; bool done = false; while (retryCount < 6) { binding = new SforceService(); binding.Timeout = 60000;LoginResult lr; try { lr = binding.login(username, password); }}} Now what should i do in this to make the authentication using AccessToken.– Himanshu JainCommented Mar 6, 2014 at 9:39
Add a comment
|
1 Answer
Refer to this.
Do your binding.login();
call inside a try catch
and check for any exceptions. Also I hope you have appended the security token at the end of the password in your
string password = "xz6isl77KwS4sO5Qhj";
-
It is currently in try catch block in my code and I am using password + security token. But the main question for me how can i use access_token in request instead of username & password because I want to OAuth 2. for accessing the access and refresh token. Commented Mar 6, 2014 at 10:27
-
Check service URLs that are using in salesforce for integrations. This may help you. Below code segment is for call particular service in C#.NET.
List<BasicNameValuePair> qsList = new ArrayList<BasicNameValuePair>(); qsList.add(new BasicNameValuePair("oauth_token", accessToken)); String queryString = URLEncodedUtils.format(qsList, HTTP.UTF_8); HttpGet userInfoRequest = new HttpGet(userIdEndpoint + "?" + queryString); HttpResponse userInfoResponse = client.execute(userInfoRequest);
– highfiveCommented Mar 6, 2014 at 10:50 -
how can I add this text of code in my Apex WebService, Like they have there own classes and functions, so for making any request to salesforce we need to call the methods from SforceService. So how can I convert the request into SforceService variable. Like we need todo new SForceService().Create(new sObject[]{}); Commented Mar 6, 2014 at 11:36
-
above code segment is not for use in Apex, but in C#.NET. Once you have logged in and got the access_token, then you need to setup an httpClient(userInforRequest above) and execute the relevent service URL with any query string parameters(which is here the access_token is one). Above code segment is to do that http call with query strings in C#– highfiveCommented Mar 7, 2014 at 18:12