Is it possible to know when an OAuth2 token will expire? Are there best practices with regard to dealing with tokens that may have expired and you don't know exactly when? You could try to use the token and then fail and then request a new token, or you could just request a new token and save yourself the trouble of a possible error. Is there no streamlined way to know for sure? The only possible good solution I know of is to simply store the date of when the token was first created, but I don't think we know how long the token will be considered good by the service.
The server may provide the expires_in
parameter alongside the access token.
Either way, you should handle error responses to invalid tokens in every request as they might be revoked by the server earlier than the normal expiration time. Theoretically it's possible that you check if the access token is valid in your first request and it will be invalid in the next one.
If the server provides a refresh token, you can request a new access token whenever you need to make sure it's valid.