I\'ve successfully built an application that fetches an access and refresh token.
In my script I check if the access token is valid and if not I then use the refresh
The reason of the "Invalid grant" error may be due to the refresh token not working. This could be because When the number of refresh tokens exceeds the limit, older tokens become invalid. If the application attempts to use an invalidated refresh token, an invalid_grant error response is returned.Here is the link for more documentation.