How to automate OAuth token generation without browser intervention?

How to automate OAuth token generation without browser intervention?

Case 1

When you develop applications to source your own information, you won't have any proper redirection URLs. In that case, you can use Self Clients to get an authorization grant code. This one-time code can exchanged for an access token and a refresh token by making POST request to /oauth/v2/token.

Case 2

When you develop a web-server based application,
  1. You have to generate grant code using /oauth/v2/auth API.
  2. In /oauth/v2/auth by default, access_type will be online. Changing the parameter as access_type=offline will give refresh token along with the access token as a response for /oauth/v2/token.
  3. Save the created refresh token in your side. You can generate access tokens using refresh tokens
  4. Once the access token expires you can regenerate them using refresh tokens automatically.
 If you have deleted the refresh token, include access_type=offline in your authorization request. Adding prompt=consent along with access_type parameter prompts the OAuth page every time when your app tries to access user details.
For detailed information, please refer to our OAuth documentation