Not sure what the goal of your app is, but to answer some of your questions-concerns:
Do tokens have to be hard coded?
No, Depending on nature of the app you are coding, you can request this data upon executing your program via webform, or textfield in a GUI or include it in another file and encrypt it or import the file it is in and use it...
I have the OAuth and access tokens hard coded right now, but the token
seems to expire every 24 hours. What can I do to renew the token
programatically?
You cant for the API key and Consumer Secret, this has to be done manually. This information should be permanent, based on https://dev.twitter.com/oauth/overview
The access Token is another story, you can use the API to request one apparently:
https://dev.twitter.com/oauth/reference/post/oauth/access_token
POST oauth/request_token Allows a Consumer application to obtain an
OAuth Request Token to request user authorization. This method
fulfills Section 6.1 of the OAuth 1.0 authentication flow. It is
strongly recommended you use HTTPS for all OAuth authorization steps.
Usage Note: Only ASCII values are accepted for the oauth_nonce
Resource URL
https://api.twitter.com/oauth/request_token
Concerning the access token expiration:
How long does an access token last? We do not currently expire access
tokens. Your access token will be invalid if a user explicitly rejects
your application from their settings or if a Twitter admin suspends
your application. If your application is suspended there will be a
note on your application page saying that it has been suspended. as
per twitter:
What do I do if an access token I have becomes invalid? You should
plan that a user’s access token may become invalid at any time and you
will need to re-authorize for that user in the case that it does.
Ensuring you handle this situation gracefully is imperative for a
quality user experience.
According to twitters documentation https://dev.twitter.com/oauth/application-only
API request contains invalid bearer token
Using an incorrect or revoked bearer token to make API requests will result in:
HTTP/1.1 401 Unauthorized
Content-Type: application/json; charset=utf-8
Content-Length: 61
...
{"errors":[{"message":"Invalid or expired token","code":89}]}
Maybe this needs resolving on twitters side? I would suggest contacting them directyl https://dev.twitter.com/solutions/customer-service