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
Ume HaaniUme Haani 

How to get the access token for querying salesforce objects

I have a requirement to access the sfdc user data (Event, contacts) from java code for which i have to pass access_token in every reqeust i make. How can i get the access token? I am following the REST Api method of querying data.
Naresh YadavNaresh Yadav
Hi Ume

You can get access token by using this request.
Note : Don't forget to replace the all the things like client_id, Client_secret...etc.

You can get client_Id and Client_secret by creating the connected app in the salesforce.
Base Url = login.salesforce.com, test.salesforce.com


https://<base_url>/services/oauth2/token?grant_type=password&client_id=<your client_Id>&client_secret=<your client_secret>&username=<your salesforce username>&password=<your salesforce password>
Ume HaaniUme Haani
Is there any way where a user can generate token from salesforce account and can be readily used in java for accessing data. 
Ume HaaniUme Haani
Naresh,
 I am not supposed to save password for doing like how you said. I am looking for a similar way like creating a service account and generating a token similar to how google does - https://developers.google.com/identity/protocols/OAuth2ServiceAccount#overview
Amit Chaudhary 8Amit Chaudhary 8
Please check below post i hope that will help you
1) http://amitsalesforce.blogspot.in/2016/05/access-token-generation-oauth-20.html

Let us know if this will help you
Naresh YadavNaresh Yadav
This is depaends on you How to setup password for your request.
But for access token it is must.
Shiny William 6Shiny William 6
How to give security token with password?.Do we need to add any symbol or something to separate password and token?.Or just add token after password?Can you please give me a sample post request for me to confirm the structure?
Thank you