Generating invoice api grant_token code from java api

Generating invoice api grant_token code from java api

Hi,

In one of my application I am using invoice API. I refered  https://www.zoho.com/invoice/api/v3/#oauth.
I can able to get refresh_token and access_token through our java API passing grant_token as code parameter. 
But I generated  the grant_token code from browser. I need to get grant_token code form API. 
I used the url  https://accounts.zoho.com/oauth/v2/authwith parameteres  from API, Its redirecting to zoho login page to authenticate.
how to achieve this, Am I need to add any authentication header in addition(I tried basic autentication: " "Basic base64encoding({userId: pwd}) but no result). 
Or is it not possible to get through API. If possible please give me brief information or example or documentation will be appreciated.

Thanks